forked from nkhuyu/leetcode-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrayCode.java
More file actions
20 lines (15 loc) · 404 Bytes
/
Copy pathGrayCode.java
File metadata and controls
20 lines (15 loc) · 404 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package gray_code;
import java.util.ArrayList;
public class GrayCode {
public class Solution {
public ArrayList<Integer> grayCode(int n) {
ArrayList<Integer> ans = new ArrayList<Integer>();
for (int i = 0; i < (1 << n); i++) {
ans.add(i ^ (i >> 1));
}
return ans;
}
}
public static class UnitTest {
}
}