Tap here to switch tabs
Problem
Submissions

Problem: Leaf-Similar Trees

Try to solve the Leaf-Similar Trees problem.

Statement

Consider all the leaves of a binary tree, evaluated from left to right order. The values of these leaves form a leaf value sequence.

Two binary trees are considered leaf similar if their leaf value sequences are identical.

Given the roots of two binary trees, root1 and root2, return true if and only if the two trees are leaf similar, otherwise return false.

Constraints:

  • The number of nodes in each tree is in the range [1,200][1, 200].

  • Both trees contain values in the range [0,200][0, 200].

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Leaf-Similar Trees

Try to solve the Leaf-Similar Trees problem.

Statement

Consider all the leaves of a binary tree, evaluated from left to right order. The values of these leaves form a leaf value sequence.

Two binary trees are considered leaf similar if their leaf value sequences are identical.

Given the roots of two binary trees, root1 and root2, return true if and only if the two trees are leaf similar, otherwise return false.

Constraints:

  • The number of nodes in each tree is in the range [1,200][1, 200].

  • Both trees contain values in the range [0,200][0, 200].