P16091 [GeeksforGeeks] Generate grey code sequences
普及-
题目描述

Given a number N, your task is to complete the function which generates all n-bit grey code sequences, a grey code sequence is a sequence such that successive patterns in it differ by one bit.
Example 1:
Input:
N = 2
Output: 00 01 11 10
Explanation: All 2-bit gray codes are
00, 01, 11, 10 such that successive
patterns in it differ by one bit.
Example 2:
Input:
N = 1
Output: 0 1

Your Task:
Complete the function generateCode() which takes an integer as input parameter and retruns an array of all N bit grey code sequence such that successive patterns in it differ by one bit.
Expected Time Complexity: O(N * 2^{N})
Expected Auxiliary Space: O(1)
Constraints:
1 ≤ N ≤ 16

输入格式

见题面

输出格式

见题面

样例输入
N = 2
样例输出
00 01 11 10