Problem · Tree
Leaf-Similar Trees
Learn this problemProblem statement
The leaf sequence of a tree lists leaf values from left to right. Return whether root1 and root2 have identical leaf sequences.
Function
leafSimilar(root1: TreeNode, root2: TreeNode) → booleanExamples
Example 1
root1 = [1,2,3]root2 = [7,2,3]return = trueBoth trees have the leaf sequence [2,3].
Constraints
- Each tree contains between
1and10000nodes. - Node values fit in a signed 32-bit integer.