Given a binary tree, find the subtree with maximum sum. Return the root of the subtree.
LintCode will print the node you return as the optimal subtree.
It's guaranteed that there is only one subtree with maximum sum and the given binary tree is not an empty tree.
Example
Example 1:
Input:{1,-5,2,0,3,-4,-5}
Output:3
Explanation:
The tree is look like this:
1
/ \
-5 2
/ \ / \
0 3 -4 -5
The sum of subtree 3 (only one node) is the maximum. So we return 3.
Example 2:
Input:{1}
Output:1
Explanation:
The tree is look like this:
1
There is one and only one subtree in the tree. So we return 1.