Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4d10895

Browse files
refactor 1104
1 parent8ce241d commit4d10895

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

‎src/main/java/com/fishercoder/solutions/_1104.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,11 @@
1212
importjava.util.List;
1313
importjava.util.Queue;
1414

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-
* */
3515
publicclass_1104 {
3616
publicstaticclassSolution1 {
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+
*/
3820
publicList<Integer>pathInZigZagTree(intlabel) {
3921
Deque<Integer>deque =buildZigZagOrderList(label);
4022
CommonUtils.printDeque(deque);
@@ -101,7 +83,9 @@ private Deque<Integer> buildZigZagOrderList(int label) {
10183
}
10284

10385
publicstaticclassSolution2 {
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+
*/
10589
publicList<Integer>pathInZigZagTree(intlabel) {
10690
List<List<Integer>>lists =buildZigZagOrderList(label);
10791
List<Integer>result =newArrayList<>();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp