public class Solution { public ArrayList grayCode(int n) { ArrayList rt = new ArrayList(); for(int i = 0; i < Math.pow(2, n); i++){ // G(N) = (B(n)/2) XOR B(n) rt.add((i / 2) ^ i); } return rt; } }