题目描述
Given to strings B and G. String B represents a binary code and string G represents a Gray Code. You need to write a program which converts binary code to gray code and vice versa.
Example 1:
Input:
B = "0011"
G = "01101"
Output:
0010
01001
Explanation:
Grey Code of 0011 is 0010.
Binary of 01101 is 01001.
Example 2:
Input:
B = "01001"
G = "01101"
Output:
01101
01001
Explanation:
Grey Code of 01001 is 01101.
Binary of 01101 is 01001.
Your Task:
You don't need to read input or print anything. Your task is to complete the functions binToGrey() and greyToBin() which takes Strings B and G as input and returns the answers.
Expected Time Complexity: O(N)
Expected Auxiliary Space: O(1)
Constraints:
1 <= |B| <= 10^{5}
1 <= |G| <= 10^{5}
输入格式
见题面
输出格式
见题面