```
class Solution {
public:
vector<int> grayCode(int n) {
vector<int> result;
if(n<0) return result;
if(n==0) {result.push_back(0); return result;}
result = grayCode(n-1);
//cout<<result.size();
int x=1<<n-1;
for(int i=result.size()-1;i>=0;i--) { //reversing the list
result.push_back(x+result[i]);
}
return result;
}
};
```