Easiest recursive solution ,look once self explanatory


#1

void fn(vector &v,TreeNode* A, int i)
{
if(A == NULL)
return ;
v[i] += A->val;
fn(v,A->left,i+1);
fn(v,A->right,i+1);
}
int Solution::solve(TreeNode* A) {
vector v(10000,0);
if(A == NULL)
return 0;
v[0] = A->val;

fn(v,A->left,1);
fn(v,A->right,1);

sort(v.rbegin(), v.rend());
return v[0];

}
If any doubt please ask.Happy Coding.