Very eacy to understand CPP solution using recursion


#1

Comment body goes here.
void helper(TreeNode* root, int level,vector& ans)
{
if(root==NULL)
return;

    ans[level] = ans[level] + root->val;
    helper(root->left,level+1,ans);
    helper(root->right,level+1,ans);
}

int Solution::solve(TreeNode* root) {

 vector<int> ans(500,0);
    helper(root,1,ans);
    
    return *max_element(ans.begin(),ans.end());

}