BFS

 /**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public List<Integer> largestValues(TreeNode root) {
List<Integer> ans = new ArrayList<Integer>();
if (root == null) return ans;
Queue<TreeNode> queue = new LinkedList<TreeNode>();
queue.add(root);
while (queue.isEmpty() != true) {
int size = queue.size();
int max = Integer.MIN_VALUE;
for (int i = 0; i < size; i++) {
TreeNode node = queue.poll();
max = Math.max(max, node.val);
if (node.left != null) queue.add(node.left);
if (node.right != null) queue.add(node.right);
}
ans.add(max);
}
return ans;
}
}

最新文章

  1. Google Code Jam 2015 R2 C
  2. HTTP 错误 500.19- Internal Server Error 错误解决方法
  3. win10 ctrl + 空格 热键取消
  4. 【Python实战02】共享Python代码到PyPI社区
  5. The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.问题解决
  6. uva 10555 - Dead Fraction)(数论)
  7. HDU3727--Jewel (主席树 静态区间第k大)
  8. uvc摄像头代码解析7
  9. url拼凑示例(具体拼凑规则由服务器定)
  10. HDOJ2000-ASCII码排序
  11. Java 获取年 月 日 时 分 秒
  12. ntp 服务:Server dropped: Strata too high
  13. element-ui的那些坑与总结
  14. Windows server 2008 r2下载地址和激活破解方法
  15. 【leetcode】部分思路整理
  16. [UE4]控制流
  17. 获取QQ头像接口
  18. MVC的项目部署成应用程序或虚拟目录路径的问题
  19. Python3基础 yield 在函数中的用法示例
  20. utf-8编码的中文看成2个字符,其他数字字符看成一个字符

热门文章

  1. char类型能否存储一个中文字符?为什么
  2. 竞赛图的得分序列 (SRM 717 div 1 250)
  3. 第0步:OracleRAC软件准备
  4. 手机控制电脑定时关机,重启WiFi
  5. Spring框架中的AOP技术----注解方式
  6. 第十三篇:multimap容器和multiset容器中的find操作
  7. JS-校验表单后提交表单的三种方法总结
  8. 什么是Base64加密?为什么要有Base64加密?
  9. linux jdk 6 版本下载
  10. 存一些可能会用得到的vue的UI框架