LeetCode 124: Binary Tree Maximum Path Sum 2
Unnecessary checks in depth_first_search()
The function depth_first_search() always returns an integer value, never None. So the check for a partial sum being None or &lt; 0 can be rewritten using max():
left_sum = max(0, depth_first_search(node.left))
right_sum = max(0, depth_first_search(node.right))