Find Bottom Left Tree Value
来源:互联网 发布:mac safari视频插件 编辑:程序博客网 时间:2024/05/29 19:41
Given a binary tree, find the leftmost value in the last row of the tree.
一层一层的搜索,返回最后一层最开始的值
class Solution {
public:int findBottomLeftValue(TreeNode* root) {
deque <TreeNode *> q1;
deque <TreeNode *> q2;
q1.push_back(root);
int val;
while(!q1.empty()||!q2.empty())
{
if(!q1.empty())
{
val=q1.front()->val;
while(!q1.empty())
{
if(q1.front()->left) q2.push_back(q1.front()->left);
if(q1.front()->right) q2.push_back(q1.front()->right);
q1.pop_front();
}
}
if(!q2.empty())
{
val=q2.front()->val;
while(!q2.empty())
{
if(q2.front()->left) q1.push_back(q2.front()->left);
if(q2.front()->right) q1.push_back(q2.front()->right);
q2.pop_front();
}
}
}
return val;
}
};
0 0
- 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
- 513:find bottom left tree value
- [leetcode]513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- [leetcode] 513. Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value
- hdu 1874 畅通工程续(dijkstr 优先队列)
- LeetCode 53. Maximum Subarray(Easy)
- 欢迎使用CSDN-markdown编辑器
- jdk1.8_121安装及运行环境配置
- Android 获取控件的宽和高
- Find Bottom Left Tree Value
- Spring使用注解注入接口实现类
- POJ 3660 Cow Contest(Floyd最短路)
- [Leetcode] Flatten Binary Tree to Linked List
- 从零单排RxAndroid系列-----定时器
- 每天晚上回家要做的事情
- 素数测试应用
- C++类中的静态成员变量和静态成员函数的作用
- 118. Pascal's Triangle