root of a binary tree. A level is the set of nodes at the same distance from the root: the root is level 0, its children are level 1, and so on.
Return a list whose i-th entry is the largest value among the nodes on level i. For an empty tree, return an empty list.root=tree_node([4, 9, 2, -3, None, 7, 1]) → [4, 9, 7]
Depth 0 holds only 4; depth 1 holds 9 and 2, so 9; depth 2 holds -3, 7 and 1, so 7.
root=tree_node([-5, None, -8]) → [-5, -8]
Each level has a single node, so that node is the level's maximum.
root=tree_node([]) → []
root=tree_node([4, 9, 2, -3, None, 7, 1])
[4, 9, 7]
Run checks the first 3 tests in your browser. Submit checks all 80 tests on the server, hidden ones included.