/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
int findBottomLeftValue(TreeNode* root) {
queue<TreeNode*>q;
if(root==NULL)return 0;
if(root->left==NULL&&root->right==NULL)return root->val;
//if(root->left==NULL&&root->right!=NULL)return root->val;
q.push(root);
int ans=0;
while(!q.empty()){
int k=1;
int cnt=q.size();
for(int i=0;i<cnt;i++){
TreeNode *p=q.front();
if(i==0)ans=p->val;
q.pop();
if(p->left)q.push(p->left);
if(p->right)q.push(p->right);
}
}
return ans;
}
};