题目描述
You are given a binary string s of length n. You have to perform binary addition of the string with '1'.
Example 1:
Input:
n = 4
s = 1010
Output: 1011
Explaination:
The decimal equivalent of given s is 10,
Adding 1 gives 11, its binary representation
is 1011.
Example 2:
Input:
n = 3
s = 111
Output: 1000
Explaination: The given number is 7.
Now 7+1 = 8, whose binary representation
is 1000.
Your Task:
You do not need to read input or print anyhthing. Your task is to complete the function binaryAdd() which takes n and s as input parameters and returns the resultant binary string after adding 1 with s.
Expected Time Complexity: O(n)
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ n ≤ 10000
输入格式
见题面
输出格式
见题面