格雷码,这是一道背答案题,记住G(i) = i ^ (i/2)即可
class Solution {
public:
vector<int> grayCode(int n) {
vector<int>v;
for(int i = 0;i< (1<<n);i++)
{
v.push_back(i ^ (i/2));
}
return v;
}
};
格雷码,这是一道背答案题,记住G(i) = i ^ (i/2)即可
class Solution {
public:
vector<int> grayCode(int n) {
vector<int>v;
for(int i = 0;i< (1<<n);i++)
{
v.push_back(i ^ (i/2));
}
return v;
}
};