Week Training: 513 Find Bottom Left Tree Value
来源:互联网 发布:手机淘宝会员怎么注册 编辑:程序博客网 时间:2024/05/22 16:54
The purpose of this problem is to find the leftmost value in the last row of the tree, what first come to me is BFS. Using a queue for auxiliary, we traverse the tree row by row, finding the leftmost value of each row and update the returned value. Until the queue is empty, which means the whole tree has been visited, the last value is the leftmost value of the bottom row. The whole process is almost like that in BFS.
class Solution {public: int findBottomLeftValue(TreeNode* root) { if(root==NULL) return 0; int Lvalue = 0; queue<TreeNode*> q; q.push(root); while(!q.empty()){ int size=q.size(); for(int i=0;i<size;i++){ TreeNode* TNode = q.front(); q.pop(); if(i==0) Lvalue = TNode->val; if(TNode->left) q.push(TNode->left); if(TNode->right) q.push(TNode->right); } } return Lvalue; }};
0 0
- Week Training: 513 Find Bottom Left Tree Value
- 513:find bottom left tree value
- 【513】 Find Bottom Left Tree Value
- No.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[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
- K-diff Pairs in an Array
- LeetCode-M-Sort Colors
- 【p1032-子串变换】解题记录
- mysql导入大量数据
- 淘宝atlas框架初探atlas-core(二):Bundle插件化
- Week Training: 513 Find Bottom Left Tree Value
- Ubuntu安装aspect
- Tensorflow学习笔记--模型保存与调取
- 十进制转任意进制
- 数据格式
- 项目中QNX的USB驱动开发的反思
- 不走索引的情况
- win10<Eclipse下Maven的配置>
- 使用 lua 编写 wireshark 协议解析插件