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

Commit0d7169f

Browse files
Update 107-Binary-Tree-Level-Order-Traversal-II.java
1 parent3a3a784 commit0d7169f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

‎java/107-Binary-Tree-Level-Order-Traversal-II.java‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
//Same just reverse in the end.
1+
//Same just reverse in the end.
22
//Reversing in the end is better than using add(0, E) in case of arraylist as it's an O(1) operation.
3+
34
classSolution {
45
publicList<List<Integer>>levelOrderBottom(TreeNoderoot) {
56
List<List<Integer>>ans =newArrayList<>();
@@ -19,13 +20,7 @@ public List<List<Integer>> levelOrderBottom(TreeNode root) {
1920
}
2021
inti =0 ,j =ans.size()-1;
2122
//reverse the list
22-
while (i<j) {
23-
List<Integer>cur =ans.get(i);
24-
ans.set(i,ans.get(j));
25-
ans.set(j,cur);
26-
i++;
27-
j--;
28-
}
23+
Collections.reverse(ans);
2924
returnans;
3025
}
3126
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp