slots
to 1, representing the slot for the root node.preorder
string by commas to process each node.slots
by 1 because each node (null or not) occupies one slot.
b. If slots
is negative at any point, return false
as this indicates more nodes than slots.
c. If the current node is not null (not a '#'
), increment slots
by 2 for the child nodes.slots
is 0. If so, return true
; otherwise, return false
.