leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0089.cpp (246B)


      1 class Solution {
      2   public:
      3     vector<int> grayCode(const int n) const {
      4         const int k = 1 << n;
      5         vector<int> res(k, 0);
      6         for (int i = 0; i < k; i++) {
      7             res[i] = i ^ (i >> 1);
      8         }
      9         return res;
     10     }
     11 };