Gray Code
Gray Code
The Gray code of current number n = (n»1) ^ n.
vector<int> grayCode(int n) {
vector<int> res;
for(int i=0;i<(1<<n);++i)
res.push_back((i>>1) ^ i);
return res;
}#math
The Gray code of current number n = (n»1) ^ n.
vector<int> grayCode(int n) {
vector<int> res;
for(int i=0;i<(1<<n);++i)
res.push_back((i>>1) ^ i);
return res;
}#math