您当前的位置: 首页 > 

对方正在debug

暂无认证

  • 4浏览

    0关注

    399博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

格雷编码(思维)

对方正在debug 发布时间:2020-02-18 19:18:39 ,浏览量:4

题目:https://leetcode-cn.com/problems/gray-code/ 参考:https://leetcode-cn.com/problems/gray-code/solution/gray-code-jing-xiang-fan-she-fa-by-jyd/

class Solution {
public:
    vector grayCode(int n) {
        /*
        *镜像反射法
        *令G[n]表示阶数为n的格雷编码
        *那么G[n+1]等于G[n] + reverse(G[n])+高位1
        */
        vector ans;
        ans.push_back(0);
        int res = 1;
        for(int k = 1;k = 0;i--)
                ans.push_back(res+ans[i]);
            res             
关注
打赏
1664895754
查看更多评论
0.0394s