Medium:Find Bottom Left Tree Value
来源:互联网 发布:可以画画的软件 编辑:程序博客网 时间:2024/06/11 14:03
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:1Example 2: Input: 1 / \ 2 3 / / \ 4 5 6 / 7Output:7Note: You may assume the tree (i.e., the given root node) is not NULL.
代码如下:
class Solution {public: int findLeftMostNode(TreeNode* root) { queue<TreeNode*> q; queue<int> level; q.push(root); level.push(0); int m=0; while(q.size()){ TreeNode *r = q.front(); q.pop(); int l = level.front(); level.pop(); if(r->left) { q.push(r->left); level.push(l+1); } if(r->right){ q.push(r->right); level.push(l+1); } if(l > m){ m = l; root = r; } } return root->val; }};
- 运用BFS算法;
- 与上一道题解法类似。
0 0
- Medium:Find Bottom Left Tree Value
- LeetCode Find Bottom Left Tree Value [Medium]
- 513[Medium]:Find Bottom Left Tree Value
- [leetcode 513. Find Bottom Left Tree Value]medium | week6
- 513. Find Bottom Left Tree Value (Medium)
- LeetCode 513. Find Bottom Left Tree Value (Medium)
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- Find Bottom Left Tree Value
- LeetCode 513. Find Bottom Left Tree Value
- C++异常捕捉两种情况-产生前-外层函数中
- Linux信号量sem_t简单实例运用
- Python项目使用memcached缓存
- 关于查询的作业题
- Flask进阶(一)——请求上下文和应用上下文完全解答(上)
- Medium:Find Bottom Left Tree Value
- 实现分页代码
- Java连接数据库步骤
- RNN简介
- 标签命名
- 关于使用bootstrap中modal和ajaxupload.js图片问题
- Arduino基础学习-tone函数
- C++11 新标准(二)
- Java学习之集合