class Solution {
public:
int findBottomLeftValue(TreeNode* root) {
queue<TreeNode*>Q;
int res;
Q.push(root);
while(!Q.empty()){
int size=Q.size();
res=Q.front()->val;
for(int i=0;i<size;++i){
TreeNode* tmpnode=Q.front();
if(tmpnode->left) Q.push(tmpnode->left);
if(tmpnode->right) Q.push(tmpnode->right);
Q.pop();
}
}
return res;
}
};
剑指 Offer II 045. 二叉树最底层最左边的值
最新推荐文章于 2022-08-26 16:02:20 发布