513. Find Bottom Left Tree Value
来源:互联网 发布:数据库resource权限 编辑:程序博客网 时间:2024/06/09 22:48
Given a binary tree, find the leftmost value in the last row of the tree.
Example 1:
Input: 2 / \ 1 3Output:1
Example 2:
Input: 1 / \ 2 3 / / \ 4 5 6 / 7Output:7
Note:You may assume the tree (i.e., the given root node) is notNULL.
Subscribe to see which companies asked this question.
Solution:
Tips:
recursion, root, right, left
Java Code:
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int findBottomLeftValue(TreeNode root) { Queue<TreeNode> queue = new LinkedList<>(); TreeNode node = root; queue.add(root); while (!queue.isEmpty()) { int queueSize = queue.size(); for (int i = 0; i < queueSize; i++) { node = queue.poll(); if (node.right != null) { queue.add(node.right); } if (node.left != null) { queue.add(node.left); } } } return node.val; } }
0 0
- LeetCode 513. Find Bottom Left Tree Value
- [leetcode]513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- [leetcode] 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- 【LeetCode】513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- Leetcode 513. Find Bottom Left Tree Value
- LeetCode 513. Find Bottom Left Tree Value
- [DFS]513. Find Bottom Left Tree Value
- LeetCode 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- 【leetcode】 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value | LeetCode
- 513. Find Bottom Left Tree Value
- 程序员:像机器一样思考
- 信息的表示和处理(待补充)
- 即拿即用-选择头像,可以选择相册,拍照,查看大图,保存到本地
- spring10
- 端游、手游服务端常用的架构是什么样的?
- 513. Find Bottom Left Tree Value
- Android中的设计模式
- MAC OS查看端口占用情况及杀死进程
- Linux Kernel 学习笔记7:同步与互斥之自旋锁
- Spark源码学习笔记1-SparkContext
- Android 网络调试 tcpip 开启方法以及10061错误解决方法
- 网络游戏服务端的多线程模型
- python 命令行:help(),'more'不是内部或外部命令,也不是可运行的程序或批处理文件
- rownum用法