C++ Level Order - easy to understand


  • 0
    S
    class Solution {
    public:
        int findBottomLeftValue(TreeNode* root) {
            queue<TreeNode*> q;
            q.push(root);
            int ans;
            while(!q.empty())
            {
                int len = q.size();
                ans = q.front()->val;
                for(int i=0;i<len;i++)
                {
                    TreeNode* temp = q.front();
                    q.pop();
                    if(temp->left)
                        q.push(temp->left);
                    if(temp->right)
                        q.push(temp->right);
                }
            }
            return ans;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.