leetcode讲解--513. Find Bottom Left Tree Value
题目
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 not NULL.
题目地址
讲解
这道题感觉挺简单的,首先我想到的是一定要选深度最大的节点,然后他要最左边的,那么我们可以先右后左的进行遍历,最后左边就可以覆盖右边了。
java代码
/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode(int x) { val = x; }* }*/
class Solution {private int result;private int maxDepth=0;public int findBottomLeftValue(TreeNode root) {inOrder(root, 0);return result;}private void inOrder(TreeNode root, int depth){if(root==null){return;}if(maxDepth<=depth){maxDepth=depth;result = root.val;}if(root.right!=null){inOrder(root.right, depth+1);}if(root.left!=null){inOrder(root.left, depth+1);}}
}
leetcode讲解--513. Find Bottom Left Tree Value相关推荐
- 【LeetCode】513. Find Bottom Left Tree Value
问题描述 问题链接:https://leetcode.com/problems/find-bottom-left-tree-value/#/description Given a binary tre ...
- Java描述 LeetCode,513. Find Bottom Left Tree Value 找左下角的值
大家好,我是河海哥,专注于后端,如果可以的话,想做一名code designer而不是普通的coder,一起见证河海哥的成长,您的评论与赞是我的最大动力,如有错误还请不吝赐教,万分感谢.一起支持原创吧 ...
- LeetCode 513. Find Bottom Left Tree Value
513. Find Bottom Left Tree Value Given a binary tree, find the leftmost value in the last row of the ...
- 513. Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input:2/ \1 3Ou ...
- [LeetCode] 513. Find Bottom Left Tree Value_ Medium tag: BFS
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input:2/ \1 3Ou ...
- Leetcode | 513. Find Bottom Left Tree Value
题目:翻转二叉树 方法①:深度优先遍历(链接) /** * Definition for a binary tree node. * struct TreeNode { * int val; * Tr ...
- 【Breadth-first Search 】513. Find Bottom Left Tree Value
输入:一颗二叉树 输出:这颗树的最下面一层最左边的节点值. 分析: 用BFS的思路解决最直观.读每一层,在每一层记录第一个元素的值.在队列中第一层:1:第二层:2,3:第三层 4,5,6.如此继续下去 ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- LeetCode讲解视频博主链接
LeetCode讲解视频博主链接 最近在YouTube上发现了一个讲解LeetCode题目的博主 花花酱,可以参考! 博客地址:http://zxi.mytechroad.com/blog/ 视频链接 ...
最新文章
- 百度Apollo 3.5是如何设计Cyber RT计算框架的?
- UWP crop image control
- Castle.ActiveRecord 学与练[3]
- 智能会议系统(18)---如何进行视频电话
- Hadoop(七)Hive基础
- mysql用户权限与安全实例_mysql用户权限管理实例分析
- 敏捷开发之团队级经验分享
- 视频画面帧的展示控件SurfaceView及TextureView对比
- springCloud Finchley 实战入门(基于springBoot 2.0.3)【五 Hystrix 服务容错保护】
- 完成中国福利彩票快三的程序设计
- 知了课堂 flask 笔记总结
- Excel表格样式CellStyle的DataFormat可选值
- 各种级数(调和、几何)总结
- 轻量级模型设计与部署总结(关键字定义/架构理解/高效CNN)
- 串口调试软件,功能强大,侦测,拦截,逆向分析串口通汛协议
- matlab给图片添加颜色条
- 在VS Code中t把分支写的代码合并到master中并提交到远程仓库github上
- Office使用的窍门和小提示
- element做树形下拉_点睛时刻:移动端需要做SEO优化吗?移动端该怎么做SEO优化?
- 十进制正整数转16进制