root of a binary tree. Check whether it is tightly packed: every level except possibly the last is completely filled, and the nodes of the last level sit side by side starting from the far left, with no gaps.
Return True if the tree is packed this way and False otherwise.root=tree_node([7, 3, 9, 1, 4]) → True
The first two levels are full, and the two nodes on the last level take the leftmost spots.
root=tree_node([7, 3, 9, None, 4]) → False
Node 3 has no left child but has a right one, so the last level has a gap on the left.
root=tree_node([7, 3, 9, 1, 4, 2, 8, 5]) → True
Node.val ≤ 1000root=tree_node([7, 3, 9, 1, 4])
True
Run checks the first 3 tests in your browser. Submit checks all 139 tests on the server, hidden ones included.