My simple c++ solution


  • 0
    K
    class Solution {
    public:
    vector<int> grayCode(int n) {
        if(n==0)return {0};
        vector<int>res;
        res=grayCode(n-1);
        for(int i=res.size()-1; i>=0; i--)res.push_back(res[i] + (1<<(n-1)));
        return res;
    }
    

    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.