class Solution {
public:
vector<int> grayCode(int n) {
vector<int> res;
//2的次方為1, n=0時, res也會有一個element
res.push_back(0);
//每次讓res中elememt的元素double
for (int i = 0; i < n; i++) {
int size = res.size();
//同一回合中, 對每個res中的element都只改變同一個bit
for (int j = size - 1; j >= 0; j--) {
res.push_back(res[j] | 1 << i);
}
}
return res;
}
};