C# bit operation


  • 0
    L
    public IList<int> GrayCode(int n) {
        IList<int> result = new List<int>(new int[]{0});
        for(int i = 1, pow = 1; i <= n; i++, pow <<= 1)
            for(int j = result.Count - 1; j >= 0; j--)
                result.Add(result[j] | pow);
        return result;
    }

Log in to reply
 

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