89. 格雷编码

89. 格雷编码,第1张

89. 格雷编码
class Solution {
public:
    vector grayCode(int n) {
        vector vec_int;
        int temp;
        vec_int.push_back(0);
        for(int i = 0; i < n; i++){
            temp = 1 << i;
            for(int j = vec_int.size() - 1; j >= 0; j--){
                vec_int.push_back(temp | vec_int[j]);
            }
        }
        return vec_int;
    }
};

Accepted
16/16 cases passed (8 ms)
Your runtime beats 60.22 % of cpp submissions
Your memory usage beats 56.27 % of cpp submissions (11.4 MB)

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5703040.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存