答案
Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).
题目
class Solution {
public List<Integer> largestValues(TreeNode root) {
if(root == null) return new ArrayList<Integer>(); ;
Queue<TreeNode> q = new LinkedList<TreeNode>();
List<Integer> list = new ArrayList<>();
q.offer(root);
while(q.size() != 0) {
int curr_size = q.size();
int max = Integer.MIN_VALUE;
for(int i = 0; i < curr_size; i++) {
TreeNode t = q.poll();
if(t.val > max)
max = t.val;
if(t.left != null) q.offer(t.left);
if(t.right != null) q.offer(t.right);
}
list.add(max);
}
return list;
}
}