给定一个二叉树的 根节点 root,请找出该二叉树的 最底层 最左边 节点的值。
假设二叉树中至少有一个节点。
class Solution {
public:
int findBottomLeftValue(TreeNode* root) {
if (root == nullptr) return 0;
queue<TreeNode*> que;
int result = 0;
que.push(root);
while (!que.empty())
{
int size = que.size();
for (int i = 0; i < size; i++)
{
TreeNode* node = que.front(); que.pop();
if(i == 0) result=node->val;
if (node->left) que.push(node->left);
if (node->right) que.push(node->right);
}
}
return result;
}
};
标签:node,int,找树,que,二叉树,左下角,root,513,size
From: https://www.cnblogs.com/lihaoxiang/p/17296066.html