|
12 | 12 | import java.util.List;
|
13 | 13 | import java.util.Queue;
|
14 | 14 |
|
15 |
| -/** |
16 |
| - * 1104. Path In Zigzag Labelled Binary Tree |
17 |
| - * |
18 |
| - * In an infinite binary tree where every node has two children, the nodes are labelled in row order. |
19 |
| - * In the odd numbered rows (ie., the first, third, fifth,...), the labelling is left to right, |
20 |
| - * while in the even numbered rows (second, fourth, sixth,...), the labelling is right to left. |
21 |
| - * |
22 |
| - * Given the label of a node in this tree, return the labels in the path from the root of the tree to the node with that label. |
23 |
| - * |
24 |
| - * Example 1: |
25 |
| - * Input: label = 14 |
26 |
| - * Output: [1,3,4,14] |
27 |
| - * |
28 |
| - * Example 2: |
29 |
| - * Input: label = 26 |
30 |
| - * Output: [1,2,6,10,26] |
31 |
| - * |
32 |
| - * Constraints: |
33 |
| - * 1 <= label <= 10^6 |
34 |
| - * */ |
35 | 15 | public class _1104 {
|
36 | 16 | public static class Solution1 {
|
37 |
| - /**This brute force solution is correct but results in TLE on LeetCode.*/ |
| 17 | + /** |
| 18 | + * This brute force solution is correct but results in TLE on LeetCode. |
| 19 | + */ |
38 | 20 | public List<Integer> pathInZigZagTree(int label) {
|
39 | 21 | Deque<Integer> deque = buildZigZagOrderList(label);
|
40 | 22 | CommonUtils.printDeque(deque);
|
@@ -101,7 +83,9 @@ private Deque<Integer> buildZigZagOrderList(int label) {
|
101 | 83 | }
|
102 | 84 |
|
103 | 85 | public static class Solution2 {
|
104 |
| - /**We'll directly compute the index of its parent, it'll be much faster this way.*/ |
| 86 | + /** |
| 87 | + * We'll directly compute the index of its parent, it'll be much faster this way. |
| 88 | + */ |
105 | 89 | public List<Integer> pathInZigZagTree(int label) {
|
106 | 90 | List<List<Integer>> lists = buildZigZagOrderList(label);
|
107 | 91 | List<Integer> result = new ArrayList<>();
|
|
0 commit comments