格雷码的定义
第二次写的,参考别人。代码写的很简洁
1 class Solution { 2 public: 3 vector<int> grayCode(int n) { 4 // Start typing your C/C++ solution below 5 // DO NOT write int main() function 6 vector<int> res; 7 res.push_back(0); 8 int highbit = 0; 9 while(n--) 10 { 11 highbit = res.size(); 12 for(int i= res.size()-1; i >= 0; i--) 13 res.push_back(highbit|res[i]); 14 } 15 return res; 16 } 17 };