We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7e559b3 commit a9f2754Copy full SHA for a9f2754
089. Gray Code.java
@@ -0,0 +1,14 @@
1
+// https://leetcode.com/problems/gray-code
2
+// magical bit manipulation see https://en.wikipedia.org/wiki/Gray_code
3
+// doubt that it's possible to come up with this solution during 30 min interview without gray code familiarity!!!
4
+// though it might be possible to look at the reflection pattern and do it the long way
5
+public class Solution {
6
+ public List<Integer> grayCode(int n) {
7
+ List<Integer> result = new LinkedList<>();
8
+
9
+ for (int i = 0; i < 1<<n; i++)
10
+ result.add(i ^ i>>1);
11
12
+ return result;
13
+ }
14
+}
0 commit comments