标签:back ret temp span push nbsp pre bsp col
1 //0010——>00010——>0011 2 //00——>0异或 3 //00——>0 4 //01——>1 5 //10——>1 6 class Solution 7 { 8 public: 9 vector<int> grayCode(int n) 10 { 11 if(n == 0) return {0}; 12 int len = pow(2,n); 13 vector<int> res; 14 for(int i = 0;i < len;i ++) 15 { 16 int a = (i >> (n - 1) & 1) ^ 0; 17 int temp = a * pow(2,n - 1); 18 for(int j = n - 2;j >= 0;j--) 19 { 20 int b = (i >> j & 1) ^ (i >> (j + 1) & 1); 21 temp += b * pow(2,j); 22 } 23 res.push_back(temp); 24 } 25 return res; 26 } 27 };
标签:back ret temp span push nbsp pre bsp col
原文地址:https://www.cnblogs.com/yuhong1103/p/12609128.html