格雷编码 class Solution { public: vector<int> grayCode(int n) { int a = 1; vector<int> res; while (n >= 0) { if (0 == res.size()) { res.push_back(0); } else { for (int i = a - 1; i >= 0; i--) { res.push_back(res[i] + a); } a *= 2; } --n; } return res; } };