leetcode513
来源:互联网 发布:淘宝大拉翅怎么戴 编辑:程序博客网 时间:2024/05/02 02:51
简单题,利用树的层序遍历寻找合适的值。
/** * 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) { if(root==NULL) return 0; else { queue<TreeNode*> treeValue; int lastPopNum; treeValue.push(root); if(root->right!=NULL) treeValue.push(root->right); if(root->left!=NULL) treeValue.push(root->left); lastPopNum=treeValue.front()->val; treeValue.pop(); while(!treeValue.empty()) { if(treeValue.front()->right!=NULL) treeValue.push(treeValue.front()->right); if(treeValue.front()->left!=NULL) treeValue.push(treeValue.front()->left); lastPopNum=treeValue.front()->val; treeValue.pop(); } return lastPopNum; } }};
0 0
- leetcode513
- leetcode513
- LeetCode513
- leetcode513 FindBottomLeftTreeValue Java
- LeetCode513. Find Bottom Left Tree Value题解
- leetcode513. Find Bottom Left Tree Value
- Leetcode513. Find Bottom Left Tree Value
- LeetCode513. Find Bottom Left Tree Value
- 24.leetCode513:Find Bottom Left Tree Value
- python--leetcode513. Find Bottom Left Tree Value
- 【Leetcode513 Find Bottom left Tree Value】树的遍历
- Openlayers之聚合标注
- javascript 函数和作用域(函数,this)(六)
- 基于FPGA的加密算法设计
- 设计模式-策略模式
- 【HPUoj】Wooden Sticks(贪心)
- leetcode513
- 配备了Linux的Exadata SL6
- VASP贋势
- sort-cut-wc详解
- 英文
- PV、UV、IP的区别
- Python遍历目录
- App页面提示样式小总结
- Jenkins快速上手