EZ PZ C++ Queue Solution


#1
int Solution::solve(TreeNode* A) {
    queue<TreeNode*> s,t;
    int m = 0;
    int temp=0;
    s.push(A);
    while(!s.empty())
    {
        TreeNode* tt = s.front();
        s.pop();
        temp+=tt->val;
        
        if(tt->left) t.push(tt->left);
        if(tt->right) t.push(tt->right);
        
        if(s.empty())
        {
            s.swap(t);
            m=max(m,temp);
            temp=0;
        }
    }
    return max(m,temp);
}