89. Gray Code

来源:互联网 发布:淘宝法院拍卖的房子 编辑:程序博客网 时间:2024/06/05 06:46
class Solution {public:    vector<int> grayCode(int n) {        int x(1<<n);        vector<int> res;        for(int i(0);i<x;i++){            //int tmp=1<<i;(意为i左移1位)            int tmp=i<<1;            //res.push_back(tmp^i>>1); >>的运算优先级大于^            res.push_back((tmp^i)>>1);        }        return res;    }};

原创粉丝点击