一、Gray Code

 1 class Solution
 2 {
 3 public:
 4     vector<int> grayCode(int n)
 5     {
 6         vector<int> result={0};
 7         if(n==0) return result;
 8         return dfs(n);
 9     }
10     vector<int> dfs(int n)
11     {
12         if(n==1)
13         {
14             vector<int> v={0,1};
15             return v;    
16         }
17         vector<int> tmp=dfs(n-1);
18         int len=tmp.size();
19         for(int i=len-1;i>=0;i--)
20         {
21             tmp.push_back(tmp[i]+len);    
22         }
23         return tmp;
24     }
25 };
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2022-02-05
  • 2021-08-24
  • 2021-06-15
猜你喜欢
  • 2022-12-23
  • 2021-08-18
  • 2021-12-26
  • 2021-08-09
  • 2022-01-07
  • 2021-04-02
  • 2021-06-24
相关资源
相似解决方案