Find Bottom Left Tree Value
来源:互联网 发布:小学英语教学软件 编辑:程序博客网 时间:2024/06/05 04:10
Given a binary tree, find the leftmost value in the last row of the tree.
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int findBottomLeftValue(TreeNode* root) { int maxlevel = 0,curlevel; TreeNode* ROOT; queue<int> level;queue<TreeNode*> q;q.push(root); level.push(0);ROOT = root;while(q.size()){TreeNode* r = q.front();curlevel = level.front();level.pop();q.pop();if(r->left){q.push(r->left);level.push(curlevel + 1); }if(r->right){q.push(r->right);level.push(curlevel + 1); }if(curlevel > maxlevel){maxlevel = curlevel;ROOT = r;}}return ROOT->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
- Sticks
- ubuntu弹出磁盘空间不足的解决方法
- Effective.Java 读书笔记(12)关于Comparable接口
- 如何在Ubuntu 16.04,Ubuntu 15.10 中安装 f.lux(f.lux支持Night Shift夜间模式)
- 改写PEB在傀儡进程执行代码
- Find Bottom Left Tree Value
- 著色器 (Shader)
- LTE BLER误块率介绍
- JAVA类细节
- 淘宝 Atlas Demo 体验
- Windows 7下硬盘安装Ubuntu 10.10
- Android Monitor GPU: GPU Profiling needs to be enabled in the device's developer options.
- 安卓自定义View基础-角度与弧度
- 数字信号处理中卷积的计算