89. Gray Code - LeetCode Solution | C++ | Go | Kotlin | Java | JS | TS | Python

raunit - in Leetcode
Explore the Gray Code problem on LeetCode with comprehensive solutions and explanations in various programming languages. Perfect for coding enthusiasts!
class Solution {
public:
    vector<int> grayCode(int n) {
        vector<int>ans;
        for(int i = 0; i<pow(2,n); i++){
            ans.push_back(i ^ (i>>1));
        }
        return ans;
    }
};
Tagsleetcodemediumc++dsamath
raunit-picture
raunit

Technical Writer at CodingKaro

Share this on
Other Blogs in Leetcode