public class Solution {

```
public List<Integer> grayCode(int n) {
List<Integer> ret = new LinkedList<Integer>();
for (int i = 0; i < Math.pow(2,n); i++)
ret.add(((i << 1) ^ i) >> 1);
return ret;
}
```

}

a gray code sequence will follow the equation:

[0, ..... (((i-1) << 1)^(i-1)) >> 1, ((i << 1) ^ i) >>1, (((i+1) << 1)^(i+1)) >> 1.......]