class Solution {
public:
vector<int> grayCode(int n) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
vector<int> res;
int total = 1 << n;
for (int i = 0; i < total; ++i)
{
res.push_back((i >> 1) ^ i);
}
return res;
}
};
[Leetcode] Gray Code
最新推荐文章于 2019-05-22 11:17:35 发布