Advertisement
Dragonkoko

Untitled

May 28th, 2019
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.31 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     /**
  4.      * @param n: a number
  5.      * @return: Gray code
  6.      */
  7.     vector<int> grayCode(int n) {
  8.         // write your code here
  9.         vector<int> res(1<<n);
  10.         for(int i =0 ; i < 1<<n; i++){
  11.             res[i] = i ^(i>>1);
  12.         }
  13.         return res;
  14.     }
  15. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement