root of a binary tree. The root sits on level 1, its children on level 2, their children on level 3, and so on.
For every level, add up the values of its nodes, and return the number of the level with the largest sum. If several levels tie, return the topmost one, i.e. the smallest number.
Node values can be negative.root=tree_node([2, -4, 9, 6, None, -1, 3]) → 3
Level sums are 2, then -4 + 9 = 5, then 6 + (-1) + 3 = 8. The largest is on level 3.
root=tree_node([5, 3, 2, -6, 1]) → 1
Levels 1 and 2 both sum to 5, level 3 sums to -5. On a tie the higher level wins, so the answer is 1.
root=tree_node([-3]) → 1
Node.val ≤ 10⁵root=tree_node([2, -4, 9, 6, None, -1, 3])
3
Run checks the first 3 tests in your browser. Submit checks all 91 tests on the server, hidden ones included.