Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- /**
- * @param n: a number
- * @return: Gray code
- */
- vector<int> grayCode(int n) {
- // write your code here
- vector<int> res(1<<n);
- for(int i =0 ; i < 1<<n; i++){
- res[i] = i ^(i>>1);
- }
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement