Leaf-Similar Trees
EasyTrees
Decode it first. Clues, constraints, pattern and plan before any code.The leaf sequence of a binary tree is the list of its leaf values (nodes with no children), read from left to right.
Given two binary trees root1 and root2, return True if their leaf sequences are the same, and False otherwise. The trees themselves can have completely different shapes.
Trees in the examples are written in level order (top to bottom, left to right), with null for a missing child, the same way the tests build them.
root1 = [1, 2, 3], root2 = [7, 8, 3, 2] → True (both have leaves 2, 3)
root1 = [1, 2, 3], root2 = [1, 3, 2] → False (2, 3 versus 3, 2)
root1 = [1, 2, 3], root2 = [1, 2] → FalseConstraints
1 <= number of nodes in each tree <= 2000 <= Node.val <= 200