题目描述
Given a binary representation in the form of string(S) of a number n, the task is to find a binary representation of n-1.
Note: n is greater than zero.
Example 1:
Input: S = "11"
Output: 10
Explanation: "11" is the binary
representation of 3 and binary
representation of 2 is "10"
Example 1:
Input: S = "1000"
Output: 111
Explanation: "1000" is the binary
representation of 8 and binary
representation of 7 is "111"
Your Task:
You don't need to read input or print anything. Complete the function binaryPreviousNumber() which takes S as input parameter and returns the string.
Expected Time Complexity:O(N)
Expected Auxiliary Space: O(N) to store resultant string
Constraints:
1 <= N <= 10^{4}
输入格式
见题面
输出格式
见题面