规律题, 如果模拟的话或者递归的话应该超级烦 2刷可以看看其他方法,个人觉得不用刷
class Solution {public: vector<int> grayCode(int n) { vector<int>ve; ve.push_back(0); if(n == 0) return ve; ve.push_back(1); if(n == 1) return ve; ve.push_back(3); ve.push_back(2); if(n == 2) return ve; int now = 2; for(int i = 3; i <= n; ++ i){ now = now << 1; for(int j = now - 1; j >= 0; -- j) ve.push_back(ve[j] + now); } return ve; }};新闻热点
疑难解答