Skip to content

Commit 1c88c1e

Browse files
refactor 102
1 parent 32a0016 commit 1c88c1e

File tree

1 file changed

+26
-25
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+26
-25
lines changed

src/main/java/com/fishercoder/solutions/_102.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,30 @@
3131
*/
3232
public class _102 {
3333

34-
public List<List<Integer>> levelOrder(TreeNode root) {
35-
List<List<Integer>> result = new ArrayList<>();
36-
if (root == null) {
37-
return result;
38-
}
39-
Queue<TreeNode> q = new LinkedList();
40-
q.offer(root);
41-
while (!q.isEmpty()) {
42-
List<Integer> thisLevel = new ArrayList();
43-
int qSize = q.size();
44-
for (int i = 0; i < qSize; i++) {
45-
TreeNode curr = q.poll();
46-
thisLevel.add(curr.val);
47-
if (curr.left != null) {
48-
q.offer(curr.left);
49-
}
50-
if (curr.right != null) {
51-
q.offer(curr.right);
52-
}
53-
}
54-
result.add(thisLevel);
55-
}
56-
return result;
57-
}
58-
34+
public static class Solution1 {
35+
public List<List<Integer>> levelOrder(TreeNode root) {
36+
List<List<Integer>> result = new ArrayList<>();
37+
if (root == null) {
38+
return result;
39+
}
40+
Queue<TreeNode> q = new LinkedList();
41+
q.offer(root);
42+
while (!q.isEmpty()) {
43+
List<Integer> thisLevel = new ArrayList();
44+
int qSize = q.size();
45+
for (int i = 0; i < qSize; i++) {
46+
TreeNode curr = q.poll();
47+
thisLevel.add(curr.val);
48+
if (curr.left != null) {
49+
q.offer(curr.left);
50+
}
51+
if (curr.right != null) {
52+
q.offer(curr.right);
53+
}
54+
}
55+
result.add(thisLevel);
56+
}
57+
return result;
58+
}
59+
}
5960
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy