Tap here to switch tabs
Problem
Submissions

Problem: Leaf-Similar Trees

Leaf-Similar Trees gives you two binary trees. Return true exactly when their leaf value sequences match from left to right, including duplicates. Otherwise, return false.

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

Leaf-Similar Trees gives you two binary trees. Return true exactly when their leaf value sequences match from left to right, including duplicates. Otherwise, return false.

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].