there are several bugs in the code:

Don't use static, I guess the OJ is running test case parallel, so if you using static, it will mess the result. for the case {3}, your code won't return 1 if running in single thread, but it could be anything since it is static when run test cases in parallel.

help method should not directly return max. if you just try to had a previous max for left tree, and right tree's result is less than left tree, return max will put the left tree's result to right tree. it should return result.

should change
{
int result = Math.max(Math.max(root.val, Math.max(root.val + left, root.val + right)), left + right + root.val);
max = (Math.max(max, result));
}
to:
{
int result = Math.max(root.val, Math.max(root.val + left, root.val + right));
max = Math.max((Math.max(max, result)), left + right + root.val);
}
when calculate the sub tree max, it should include left+right+self. since we only can choose one path when it's parent calculate the result.