We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0a93f17 commit c03fd09Copy full SHA for c03fd09
2018.12.05-leetcode102/FFFro.md
@@ -0,0 +1,27 @@
1
+import java.util.ArrayList;
2
+import java.util.List;
3
+
4
+class Solution {
5
+ public List<List<Integer>> levelOrder(TreeNode root) {
6
+ List<List<Integer>> list = new ArrayList<>();
7
+ if (root == null) {
8
+ return list;
9
+ }
10
+ levelOrder(root,0,list);
11
12
13
14
+ private void levelOrder(TreeNode root, int i, List<List<Integer>> list) {
15
+ if (root == null)
16
+ return;
17
+ if (list.size() == i){
18
+ List<Integer> a = new ArrayList<>();
19
+ a.add(root.val);
20
+ list.add(a);
21
+ }else {
22
+ list.get(i).add(root.val);
23
24
+ levelOrder(root.left,i+1,list);
25
+ levelOrder(root.right,i+1,list);
26
27
+}
0 commit comments