原题

Given a binary tree, find the leftmost value in the last row of the tree.

Example 1:

Input:

2

/

1 3

Output:

1

Example 2:

Input:

        1
/ \
2 3
/ / \
4 5 6
/

7

Output:

7

Note: You may assume the tree (i.e., the given root node) is not NULL.

解析

查找最后一层最左侧的叶子节点的值

思路

BFS,从右向左搜索

解法(同最优解)

public int findBottomLeftValue(TreeNode root) {
Queue<TreeNode> queue = new LinkedList<>();
TreeNode last = root;
queue.offer(root);
while (!queue.isEmpty()) {
last = queue.poll();
if (last.right != null) {
queue.offer(last.right);
}
if (last.left != null) {
queue.offer(last.left);
}
}
return last.val;
}

【leetcode】513.Find Bottom Left Tree Value的更多相关文章

  1. 【LeetCode】513. Find Bottom Left Tree Value 解题报告(Python & C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS DFS Date 题目地址:https:// ...

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

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

  3. 【LeetCode】99. Recover Binary Search Tree 解题报告(Python)

    [LeetCode]99. Recover Binary Search Tree 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https://leetcode.com/p ...

  4. 【LeetCode】 99. Recover Binary Search Tree [Hard] [Morris Traversal] [Tree]

    Two elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing ...

  5. 【LeetCode】105 & 106. Construct Binary Tree from Inorder and Postorder Traversal

    题目: Given inorder and postorder traversal of a tree, construct the binary tree. Note:You may assume ...

  6. 【LeetCode】Maximum Depth of Binary Tree(二叉树的最大深度)

    这道题是LeetCode里的第104道题. 给出题目: 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定 ...

  7. 【LeetCode】1008. Construct Binary Search Tree from Preorder Traversal 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 日期 题目地址:https://leetcod ...

  8. 【LeetCode】993. Cousins in Binary Tree 解题报告(C++ & python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://le ...

  9. 【LeetCode】98. Validate Binary Search Tree 解题报告(Python & C++ & Java)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 递归 BST的中序遍历是有序的 日期 题目地址:ht ...

随机推荐

  1. sqoop import mysql to hive table:GC overhead limit exceeded

    1. Scenario description when I use sqoop to import mysql table into hive, I got the following error: ...

  2. 【翻译】Flink Table Api & SQL ——Streaming 概念

    本文翻译自官网:Streaming 概念  https://ci.apache.org/projects/flink/flink-docs-release-1.9/dev/table/streamin ...

  3. Redis项目实战

    1.显示最新的项目列表 下面这个语句常用来显示最新项目,随着数据多了,查询毫无疑问会越来越慢. SELECT * FROM foo WHERE ... ORDER BY time DESC LIMIT ...

  4. Win10安装Golang

    首先去这个网站下载Golang的安装包:https://studygolang.com/dl 因为我的系统是Win10专业版64位,所以我选择了对应的Windows的安装包进行下载: 下载好安装包之后 ...

  5. Java学习,从入门到放弃(二)Linux配置mvn

    其实网上的教程很多,随便拿一个,比如:https://www.cnblogs.com/chuijingjing/p/10430649.html 但在实践过程中,发现可能需要将JAVA_HOME也加到 ...

  6. 实验1 C 语言开发环境使用和数据类型、运算符、表达式

    # include <stdio.h> int main() { int x; printf("x:\n"); scanf("%d",&x) ...

  7. eclipse英语单词1

    short cut bar 捷径,快捷方法 menu bar 菜单栏 tool bar 工具栏 workbench window 工作台窗口 perspective 透视 editor 编辑器 con ...

  8. 最近邻与K近邻算法思想

    在关于径向基神经网络的一篇博文机器学习之径向基神经网络(RBF NN)中已经对最近邻思想进行过描述,但是写到了RBF中有些重点不够突出,所以,这里重新对最近邻和K近邻的基本思想进行介绍,简洁扼要的加以 ...

  9. 使用mysql连接django时,需要的步骤以及错误解决办法

    django默认使用的sqlite3,更改为SQL时需要按照如下操作进行 1.在settings.py中的78行进行更改 DATABASES = { 'default': { 'ENGINE': 'd ...

  10. uwsgi03----直接部署

    1.http 和 http-socket的使用上有一些区别: http: 自己会产生一个http进程(可以认为与nginx同一层)负责路由http请求给worker, http进程和worker之间使 ...