We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 397169e commit 6b92fd1Copy full SHA for 6b92fd1
solution/1104.Path In Zigzag Labelled Binary Tree/Solution.java
@@ -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