Created
August 22, 2016 23:57
-
-
Save leearmee35/d3222c4fe1fd593b2f4c198ca60f5e37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public List<Integer> grayCode(int n) { | |
ArrayList<Integer> res = new ArrayList<Integer>(); | |
res.add(0); | |
for(int i=0;i<n;i++){ | |
int add = 1<<i; | |
int k = res.size()-1; | |
for(int j=k;j>=0;j--){ | |
res.add(add+res.get(j)); | |
} | |
} | |
return res; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment