Share my solution(392ms)

  • 1
    public List<Integer> grayCode(int n) {
    	List<Integer> li = new LinkedList<Integer>();
    	for(int i = 0;i<Math.pow(2, n);i++)
    		int i2 = i>>1;
    		int x = i^i2;
        return li;

    My solution is based on how to transform binary code into gray code. Google what gray code is, then it's easy to understand.

Log in to reply

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