Skip to content

Commit 6b92fd1

Browse files
authored
Create Solution.java
1 parent 397169e commit 6b92fd1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public List<Integer> pathInZigZagTree(int label) {
3+
List<Integer> res = new ArrayList<>();
4+
int n = Integer.highestOneBit(label);
5+
while (label > 0) {
6+
res.add(label);
7+
int pos = ((n << 1) - 1 - label) >> 1;
8+
label = (n >> 1) + pos;
9+
n >>= 1;
10+
}
11+
Collections.reverse(res);
12+
return res;
13+
}
14+
}

0 commit comments

Comments
 (0)