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

Raunit Verma - in Leetcode
Views: 4

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 Verma-picture
Raunit Verma

Technical Writer at CodingKaro

Share this on
CodingKaro Poster
CodingKaro
4.7

3K+ Downloads

One of its unique features is an automated coding contest reminder, which sets alarms for upcoming coding contests on popular platforms like CodeChef, CodeForces, and LeetCode, without the need for user input. This feature ensures that users never miss a coding contest and can stay updated with the latest coding challenges.

Download CodingKaro
Other Blogs in Leetcode