bfs clean solution


  • 0
    X
        int findBottomLeftValue(TreeNode* root) 
        {
            queue<TreeNode*> table;
            table.push(root);
            vector<int> res;
            while(!table.empty())
            {
                res.clear();
                int len=table.size();
                for(int i=0;i<len;i++)
                {
                    TreeNode* tmp=table.front();
                    table.pop();
                    res.push_back(tmp->val);
                    if(tmp->left)
                        table.push(tmp->left);
                    if(tmp->right)
                        table.push(tmp->right);
                }
            }
            return res[0];
        }
    

Log in to reply
 

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