Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 831 Bytes

Find Bottom Left.md

File metadata and controls

41 lines (28 loc) · 831 Bytes
int findBottomLeftValue(TreeNode* root) {

        int ans=root->val;
        queue<TreeNode*>q;

        q.push(root);

        while(q.size()!=0)
        {
            int n=q.size();
            

            for(int i=0;i<n;i++)
            {
                TreeNode* cur=q.front();
                q.pop();

                if(i==0)
                    ans=cur->val;

                if(cur->left!=NULL)
                {
                    q.push(cur->left);
                }
                
                if(cur->right!=NULL)
                {
                    q.push(cur->right);
                }

                
            }
        }

        return ans;
    }