The solution does not work for the tree below (correct answer is -4 but the solution gives -1):
TreeNode root = new TreeNode(-5);
root.left = new TreeNode(-1);
root.left.left = new TreeNode(-3);
root.left.right = new TreeNode(-8);
The issue is, localMax must include one child as long as one of them is non-null, if both children are null we should not update globalMax at all.