c++,clear queue solution


  • 0
    9

    //every the first of the queue may be the result

    public:
        int findBottomLeftValue(TreeNode* root) {
            int result;
            queue<TreeNode*>  q;
            q.push(root);
            while(!q.empty())
            {
                result=q.front()->val;
                int count=q.size();
                for(int i=0;i<count;i++)
                {
                    if(q.front()->left)  q.push(q.front()->left);
                    if(q.front()->right)    q.push(q.front()->right);
                    q.pop();
                }
            }
            return result;
        }
    };

Log in to reply
 

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