root of a binary tree. For each level, first the root, then its children, then its grandchildren and so on, compute the mean of the node values on that level.
Return the means from top to bottom. An answer is accepted if every number is within 10⁻⁵ of the exact value.root=tree_node([10, 4, 7, None, 1, -2, 8]) → [10.0, 5.5, 2.3333333333333335]
Level 0: 10. Level 1: (4 + 7) / 2 = 5.5. Level 2: (1 − 2 + 8) / 3 ≈ 2.33333.
root=tree_node([6]) → [6.0]
A single node makes one level with mean 6.
Node.val ≤ 2³¹ − 1root=tree_node([10, 4, 7, None, 1, -2, 8])
[10.0, 5.5, 2.3333333333333335]
Run checks the first 3 tests in your browser. Submit checks all 95 tests on the server, hidden ones included.