1 public class Solution { 2 public ArrayList<Integer> grayCode(int n) { 3 ArrayList<Integer> res = new ArrayList<Integer>(); 4 res.add(0); 5 for(int i=0;i<n;i++){ 6 int highest = 1<<i; 7 int len = res.size(); 8 for(int j=len-1;j>=0;j--){ 9 res.add(highest+res.get(j)); 10 } 11 } 12 return res; 13 } 14 }
原文:http://www.cnblogs.com/krunning/p/3547423.html