Very easy c++ iterative level by level


#1

int Solution::solve(TreeNode* A) {
int sum=INT_MIN;
queue<TreeNode*>q;
q.push(A);
while(!q.empty())
{
int s=0;
int k=q.size();
for(int i=0;i<k;i++)
{
TreeNode *temp = q.front();
q.pop();
s+=temp->val;
if(temp->left)
q.push(temp->left);
if(temp->right)
q.push(temp->right);
}
sum = max(s,sum);
}
return sum;
}