515. Find Largest Value in Each Tree Row
来源:互联网 发布:美容保健品 知乎 编辑:程序博客网 时间:2024/06/17 20:49
You need to find the largest value in each row of a binary tree.
Example:
Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]
Subscribe to see which companies asked this question.
/** * 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> re = new ArrayList<Integer>();if (root == null)return re;LinkedList<TreeNode> data = new LinkedList<TreeNode>();data.add(root);while (!data.isEmpty()) {int max = Integer.MIN_VALUE;int i = data.size();while (i > 0) {TreeNode temp = data.pop();max = Math.max(max, temp.val);if (temp.left != null)data.add(temp.left);if (temp.right != null)data.add(temp.right);i--;}re.add(max);}return re; }}
0 0
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- Find Largest Value in Each Tree Row
- LeetCode 515. Find Largest Value in Each Tree Row
- 515. Find Largest Value in Each Tree Row
- LeetCode OJ 515. Find Largest Value in Each Tree Row
- 515. Find Largest Value in Each Tree Row
- 515. Find Largest Value in Each Tree Row
- week3-NO.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
- 神经网络/深度学习框架
- 从android:onClick属性谈运行时注解在Android中的运用
- Unity引用dll后发布报错"Encoding name 'IBM437' not supported"
- 环形缓冲区的应用ringbuffer
- Spring MVC 生成验证码
- 515. Find Largest Value in Each Tree Row
- 你真的了解try{ return }finally{}中的return吗?
- 证道歌
- 计161_Problem Y: C语言实验--字符变量的输入输出
- 呆萌程序猿的恋爱奇葩说
- Installshield windows注册表实时生效
- 算法提高 勾股数
- 对象引用
- ~粘滞位~