Leetcode 89 Solution
This article provides solution to leetcode question 89 (gray-code)
Access this page by simply typing in "lcs 89" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/gray-code
Solution
class Solution {
public:
vector<int> grayCode(int n) {
vector<int> res;
res.push_back(0);
for (int i = 0; i < n; i++)
{
int m = res.size();
for (int j = m - 1; j >= 0; j--)
{
res.push_back(res[j] | (1 << i));
}
}
return res;
}
};