算法分析与设计丨第四周丨LeetCode(7)——Find Bottom Left Tree Value(Medium)
来源:互联网 发布:淘宝客网站怎样推广 编辑:程序博客网 时间:2024/05/21 06:24
层次遍历
题目链接:https://leetcode.com/problems/find-bottom-left-tree-value/description/
/** * 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) { queue<TreeNode*> my_que; my_que.push(root); int record; while(!my_que.empty()) { int num = my_que.size(); for(int i = 0;i<num;++i) { TreeNode* temp = my_que.front(); my_que.pop(); if(i == 0) record = temp->val; if(temp->left!=NULL) my_que.push(temp->left); if(temp->right!=NULL) my_que.push(temp->right); } } return record; }};
阅读全文
0 0
- 算法分析与设计丨第四周丨LeetCode(7)——Find Bottom Left Tree Value(Medium)
- 算法分析与设计第四周:513. Find Bottom Left Tree Value
- LeetCode Find Bottom Left Tree Value [Medium]
- 算法分析与设计丨第四周丨LeetCode(8)——Binary Tree Level Order Traversal(Medium)
- 算法课 第四周 Find Bottom Left Tree Value
- 513. Find Bottom Left Tree Value (Medium)
- 算法分析与设计丨第三周丨LeetCode(6)——Find Largest Value in Each Tree Row(Medium)
- [leetcode 513. Find Bottom Left Tree Value]medium | week6
- LeetCode 513. Find Bottom Left Tree Value (Medium)
- 第十周算法分析与设计: Find Bottom Left Tree Value
- 【算法分析与设计】【第十五周】513. Find Bottom Left Tree Value
- Medium:Find Bottom Left Tree Value
- 513[Medium]:Find Bottom Left Tree Value
- 【leetcode】513. Find Bottom Left Tree Value(Python & C++)
- 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
- Shiro 的身份认证-Realm
- 关于AppCompatSpinner在某些机型使用popupBackground显示异常的解决方案
- 如何判断Javascript对象是否存在
- 【Java集合类】Vector解析
- 不正常团伙 (离线线段树 莫队)
- 算法分析与设计丨第四周丨LeetCode(7)——Find Bottom Left Tree Value(Medium)
- Error running Unnamed: Address localhost:8080 is already in use
- 17、Selenium + Python 实现 UI 自动化测试-等待
- BZOJ 1000: A+B Problem
- Makefile 书写
- 简单阐述java访问控制
- URL安全的字符串base64编码和解码
- 【go 通道】go语言通道channel
- 跑马灯的一些使用心得