For the Nth element in the gray code sequence,

the following equation can be used

N ^ floor(N/2)

Here's my code snippet:

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