root of a binary tree. The height of a subtree is the number of nodes on the longest path from its top node down to a leaf; an empty subtree has height 0.
Call a tree evenly grown if at **every** node the heights of the left and right subtrees differ by at most 1. Return True if the tree is evenly grown and False otherwise.root=tree_node([4, 2, 9, 1, None, 7, 11]) → True
Node 2 has a left subtree of height 1 and nothing on the right, a difference of 1, which is allowed. Both branches of the root have height 2.
root=tree_node([6, 3, None, 2, None, 1]) → False
At the root 6 the left side is the chain 3 → 2 → 1 of height 3 and the right side is empty. A difference of 3 means the tree is lopsided.
root=tree_node([]) → True
An empty tree has no node that could break the rule.
Node.val ≤ 10⁴root=tree_node([4, 2, 9, 1, None, 7, 11])
True
Run checks the first 3 tests in your browser. Submit checks all 108 tests on the server, hidden ones included.