Leetcode 513 Find Bottom Left Tree Value
来源:互联网 发布:plc和单片机哪个工资高 编辑:程序博客网 时间:2024/05/22 15:24
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.
要找到最后一排最左边的node,需要从right到left进行遍历/** * 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<>(); queue.add(root); while(!queue.isEmpty()){ root = queue.poll(); if(root.right != null){ queue.add(root.right); } if(root.left != null){ queue.add(root.left); } } return root.val; }}
阅读全文
0 0
- LeetCode #513: Find Bottom Left Tree Value
- Leetcode 513 Find Bottom Left Tree Value
- leetcode 513 Find Bottom Left Tree Value
- LeetCode#513 Find Bottom Left Tree Value
- LeetCode 513. Find Bottom Left Tree Value
- [leetcode]513. Find Bottom Left Tree Value
- [leetcode] 513. Find Bottom Left Tree Value
- 【LeetCode】513. Find Bottom Left Tree Value
- Leetcode 513. Find Bottom Left Tree Value
- LeetCode 513. Find Bottom Left Tree Value
- LeetCode 513. Find Bottom Left Tree Value
- 【leetcode】 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value | LeetCode
- leetcode-513. Find Bottom Left Tree Value
- LeetCode 513. Find Bottom Left Tree Value
- leetcode 513. Find Bottom Left Tree Value
- leetcode 513. Find Bottom Left Tree Value
- [leetcode]513. Find Bottom Left Tree Value
- 如何设置xampp的phpmyadmin外网访问?
- Lombok:让JAVA代码更优雅
- 户外决策带你上王者
- mongo教程-基础操作命令篇
- php-人员权限管理(RBAC)
- Leetcode 513 Find Bottom Left Tree Value
- redis安装配置jedis客户端访问redis相关问题总结
- php入门学习-----数组
- Matlab代码转C++—— mwArray
- Tomcat环境变量配置
- Check failed: axis_index < num_axes() (1 vs. 1) axis 1 out of range for 1-D Blob with shape
- Ubuntu下SSH安装或设置
- 百度地图1,2,3面
- 6.7-Django-笔记--ORM解释--未完!