Problem · Tree

Leaf-Similar Trees

Learn this problem
EasyAtlassian logoAtlassianFULLTIMEOA

Problem 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) → boolean

Examples

Example 1

root1 = [1,2,3]root2 = [7,2,3]return = true

Both trees have the leaf sequence [2,3].

Constraints

  • Each tree contains between 1 and 10000 nodes.
  • Node values fit in a signed 32-bit integer.

More Atlassian problems

drafts saved locally
public boolean leafSimilar(TreeNode root1, TreeNode root2) {
  // Write your code here.
}
root1[1,2,3]
root2[7,2,3]
expectedtrue
checking account