Dfs,recursion,wtf15charsneeded


#1

map<int,int>mp;

void dfs(TreeNode* A, int dep){
if(A==NULL)return;
mp[dep]+= A->val ;
dfs(A->left,dep+1);
dfs(A->right,dep+1);
}

int Solution::solve(TreeNode* A) {
mp.clear();
dfs(A,0);
int mx=A->val;
for(auto it=mp.begin();it!=mp.end();it++){
mx=max(mx,it->second);
}
return mx;
}