Analysis:
The depth first search can extract the maximum sum from buttom to the top, that is ret = max{root+non-left+non-right, left+right}
use the return value to switch the side.
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class Solution(object): |