@Yupeng_Su To make your explanation more clear. It's true that this maxValue = Math.max(maxValue, left + right + node.val); will give us the max value from those 3 cases. The maxValue in this equation is the result after comparing case 1 and 2, and this equation compares the max(case 1 and 2) to case 3. dfs(root.left) returns the max(root.left.left, root.left.right) + root.val, but since root value can be negative, so we further compare it to 0, which means it stopped from accumulating values on this path. (this branch is trimmed) ðŸ˜Š

Binary Tree Maximum Path Sum