In a binary tree, a path is any sequence of connected nodes where each node appears only once.
The path does not have to go through the root.
The path sum is the total of all node values along that path.
Return the highest possible path sum for any non-empty path in the tree.
Input: root = [5,4,8,11,null,13,4]
Output: 48
Explanation:
The best path is 11 → 4 → 5 → 8 → 13 with a sum of 48.
Input: root = [-3]
Output: -3
Explanation:
Only one node exists, so the maximum path sum is -3.
Input: root = [10,2,10,20,1,-25,3,4]
Output: 42
Explanation:
The best path is 20 → 2 → 10 → 10, giving a sum of 42.
Accepted:
Submission: