My java code with XOR


  • 1
    W
    public List<Integer> grayCode(int n) {
        List<Integer> list = new ArrayList<Integer>();
        for(int i=0;i<Math.pow(2,n);i++){
            int temp = i>>1;
            list.add(temp ^ i);
        }
        return list;
    }
    

    }


Log in to reply
 

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