-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleetcode_102.java
38 lines (34 loc) · 995 Bytes
/
leetcode_102.java
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
package leetcode;
import com.sun.prism.shader.Texture_Color_AlphaTest_Loader;
import java.util.*;
public class leetcode_102 {
}
class Lee_102 {
/**
*
* @param root
* @return
*/
public List<List<Integer>> levelOrder(TreeNode root) {
List<List<Integer>> res = new ArrayList<>();
Deque<TreeNode> deque = new LinkedList<>();
if(root == null)
return res;
deque.addFirst(root);
while(!deque.isEmpty()){
int size = deque.size();
ArrayList<Integer> tem = new ArrayList<>();
while(size>0){
TreeNode node = deque.pollLast();
tem.add(node.val);
if(node.left!= null)
deque.addFirst(node.left);
if(node.right != null)
deque.addFirst(node.right);
size--;
}
res.add(tem);
}
return res;
}
}