题目:https://leetcode-cn.com/problems/gray-code/submissions/
代码:
class Solution {
public:
vector grayCode(int n) {
int size = 1 << n;
vector res;
for (int i = 0; i < size; i++)
{
int a = i ^ (i >> 1);
res.push_back(a);
}
return res;
}
};

结果:
leetcode 腾讯精选-89

相关文章:

  • 2021-05-08
  • 2021-04-30
  • 2021-12-01
  • 2021-04-07
  • 2021-05-28
  • 2021-11-21
  • 2021-11-25
  • 2021-10-14
猜你喜欢
  • 2021-04-19
  • 2021-09-11
  • 2021-09-29
  • 2021-06-17
  • 2021-12-17
  • 2021-04-12
  • 2022-12-23
相关资源
相似解决方案