[leetCode刷题笔记]515. Find Largest Value in Each Tree Row
来源:互联网 发布:js日期格式化工具 编辑:程序博客网 时间:2024/05/29 13:46
515. Find Largest Value in Each Tree Row
使用递归,通过一个数d记录所处树的深度。还有通过比较d和list的长度来确定是添加一个新值,还是比较旧值与新值的大小。注意List的引用一直不变
public class Solution { public List<Integer> largestValues(TreeNode root) { List<Integer> res = new ArrayList<Integer>(); helper(root, res, 0); return res; } private void helper(TreeNode root, List<Integer> res, int d) { if (root == null) { return; } if (d == res.size()) { res.add(root.val); } else { res.set(d, Math.max(res.get(d), root.val)); } helper(root.left, res, d + 1); helper(root.right, res, d + 1); }}
0 0
- LeetCode笔记:515. Find Largest Value in Each Tree Row
- [leetCode刷题笔记]515. Find Largest Value in Each Tree Row
- LeetCode 515. Find Largest Value in Each Tree Row
- LeetCode OJ 515. Find Largest Value in Each Tree Row
- [leetcode] 515. Find Largest Value in Each Tree Row
- 【LeetCode】515. Find Largest Value in Each Tree Row
- LeetCode;515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode-515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- LeetCode 515. Find Largest Value in Each Tree Row (C++)
- leetcode 515. Find Largest Value in Each Tree Row
- LeetCode#515. Find Largest Value in Each Tree Row
- leetcode 515. Find Largest Value in Each Tree Row
- LeetCode 515. Find Largest Value in Each Tree Row
- IMWeb训练营作业
- hdu1063 Exponentiation 高精度小数
- 字节流与字符流的区别
- 判断二叉树是不是对称的
- PHP高效率写法(详解原因)
- [leetCode刷题笔记]515. Find Largest Value in Each Tree Row
- opencv基础数据结构 CvPoint & CvSize & CvRect & CvScalar & CvArr & CvMat
- idea gradle-view 依赖分析无法使用
- 归并排序
- 快学scala笔记之02-类
- 读书笔记:预解式
- Andriod Service 启动与绑定的区别
- 解读uCos中优先级判定表OSUnMapTbl原理
- SSM(Spring + Spring MVC +Mybatis)的Redis缓存,JedisPool配置