Untitled
lass Solution { public: int solve(TreeNode* root,int ans){ if(root==NULL) return ans; //ans=max(ans,root->val); int left =solve(root->left,ans+root->val); int right=solve(root->right,ans+root->val); return max(left,right); } int maxPathSum(TreeNode* root) { int ans=0; return solve(root,ans); } };