```
class Solution {
public:
vector<int> grayCode(int n) {
vector<int> result;
result.push_back(0);
for(int i=0;i<n;i++){
// mirror the result with shift ith digit to 1
for(int j=result.size()-1;j>=0;j--){
int cur=result[j]+(1<<i);
result.push_back(cur);
}
}
return result;
}
};
```