-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem107.java
More file actions
55 lines (41 loc) · 1.13 KB
/
Problem107.java
File metadata and controls
55 lines (41 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.leetcode.problems;
import com.leetcode.datastructs.TreeNode;
import java.util.*;
class Solution107 {
public List<List<Integer>> levelOrderBottom(TreeNode root) {
List<List<Integer>> res = new LinkedList<>();
if(root==null)
{
return res;
}
Queue<TreeNode> q = new LinkedList<>();
q.add(root);
while (!q.isEmpty())
{
int sz = q.size();
List<Integer> list = new LinkedList<>();
for (int i = 0; i < sz; i++) {
TreeNode cur = q.poll();
list.add(cur.val);
if(cur.left!=null)
{
q.offer(cur.left);
}
if(cur.right!=null)
{
q.offer(cur.right);
}
}
res.add(0, list);
}
return res;
}
}
public class Problem107 {
public static void main(String[] args) {
LinkedList<Integer> integers = new LinkedList<>();
integers.add(0,4);
integers.add(0,84);
System.out.println("hello");
}
}