Solved using queue


#1

int Solution::solve(TreeNode* A) {
if(A==NULL)
return 0;
queue<TreeNode*>q;
q.push(A);
int sum=A->val,count=1,temp=0;
TreeNode* root=NULL;
while(!q.empty()){
count=q.size();
temp=0;
while(count–){
root=q.front();
q.pop();
temp += root->val;
if(root->left){
q.push(root->left);
}
if(root->right){
q.push(root->right);
}
}
sum=max(sum,temp);
}
return sum;
}s here.