题目

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相关推荐

  1. 【LeetCode】513. Find Bottom Left Tree Value

    问题描述 问题链接:https://leetcode.com/problems/find-bottom-left-tree-value/#/description Given a binary tre ...

  2. Java描述 LeetCode,513. Find Bottom Left Tree Value 找左下角的值

    大家好,我是河海哥,专注于后端,如果可以的话,想做一名code designer而不是普通的coder,一起见证河海哥的成长,您的评论与赞是我的最大动力,如有错误还请不吝赐教,万分感谢.一起支持原创吧 ...

  3. 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 ...

  4. 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 ...

  5. [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 ...

  6. Leetcode | 513. Find Bottom Left Tree Value

    题目:翻转二叉树 方法①:深度优先遍历(链接) /** * Definition for a binary tree node. * struct TreeNode { * int val; * Tr ...

  7. 【Breadth-first Search 】513. Find Bottom Left Tree Value

    输入:一颗二叉树 输出:这颗树的最下面一层最左边的节点值. 分析: 用BFS的思路解决最直观.读每一层,在每一层记录第一个元素的值.在队列中第一层:1:第二层:2,3:第三层 4,5,6.如此继续下去 ...

  8. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  9. LeetCode讲解视频博主链接

    LeetCode讲解视频博主链接 最近在YouTube上发现了一个讲解LeetCode题目的博主 花花酱,可以参考! 博客地址:http://zxi.mytechroad.com/blog/ 视频链接 ...

最新文章

  1. 百度Apollo 3.5是如何设计Cyber RT计算框架的?
  2. UWP crop image control
  3. Castle.ActiveRecord 学与练[3]
  4. 智能会议系统(18)---如何进行视频电话
  5. Hadoop(七)Hive基础
  6. mysql用户权限与安全实例_mysql用户权限管理实例分析
  7. 敏捷开发之团队级经验分享
  8. 视频画面帧的展示控件SurfaceView及TextureView对比
  9. springCloud Finchley 实战入门(基于springBoot 2.0.3)【五 Hystrix 服务容错保护】
  10. 完成中国福利彩票快三的程序设计
  11. 知了课堂 flask 笔记总结
  12. Excel表格样式CellStyle的DataFormat可选值
  13. 各种级数(调和、几何)总结
  14. 轻量级模型设计与部署总结(关键字定义/架构理解/高效CNN)
  15. 串口调试软件,功能强大,侦测,拦截,逆向分析串口通汛协议
  16. matlab给图片添加颜色条
  17. 在VS Code中t把分支写的代码合并到master中并提交到远程仓库github上
  18. Office使用的窍门和小提示
  19. element做树形下拉_点睛时刻:移动端需要做SEO优化吗?移动端该怎么做SEO优化?
  20. 十进制正整数转16进制

热门文章

  1. hdu6086(AC 自动机)
  2. MarkDown、Vim双剑合璧
  3. Kotlin教程 - 收藏集 - 掘金
  4. html----学习笔记
  5. Linux 下的终端
  6. 普通用户通过Putty密钥方式登录
  7. ASP.NET MVC模型绑定int超出范围时
  8. groovy环境搭建,配置报错
  9. thinking in java(第七章)
  10. 史上最强大的僵尸网络 Dark_nexus 横空出世