Skip to content

Instantly share code, notes, and snippets.

@leearmee35
Created August 22, 2016 23:57
Show Gist options
  • Save leearmee35/d3222c4fe1fd593b2f4c198ca60f5e37 to your computer and use it in GitHub Desktop.
Save leearmee35/d3222c4fe1fd593b2f4c198ca60f5e37 to your computer and use it in GitHub Desktop.
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