Practice/Snowflake/Leetcode 872. Leaf-Similar Trees
CodingMust
Given the roots of two binary trees, determine whether they have identical leaf value sequences. A leaf is defined as a node with no children. The leaf value sequence is the ordered list of all leaf node values when traversed from left to right.
Return true if and only if the two trees produce the same leaf value sequence when their leaves are read from left to right.
true if the sequences match, false otherwise[1, 200][0, 200]Example 1:
`
Input:
Tree1: 3
/
5 1
/ \ /
6 2 9 8
/
7 4
Tree2: 3
/
5 1
/ \
6 7 2
/ \ /
4 9 8 null
Output: true Explanation: Both trees have the leaf sequence [6, 7, 4, 9, 8] when read from left to right. `
Example 2:
`
Input:
Tree1: 1
/
2 3
Tree2: 1
/
3 2
Output: false Explanation: Tree1 has leaf sequence [2, 3] while Tree2 has leaf sequence [3, 2]. `
Example 3:
` Input: Tree1: 1
Tree2: 1
Output: true Explanation: Both trees consist of a single leaf node with value 1. `