872. Leaf-Similar Trees
給你兩個樹,如果該兩個樹從左邊看到右邊的所有葉子節點都相等就返回true否則false
https://assets.leetcode.com/uploads/2020/09/03/leaf-similar-1.jpg
Input: root1 = [3,5,1,6,2,9,8,null,null,7,4], root2 =
[3,5,1,6,7,4,2,null,null,null,null,null,null,9,8]
Output: true
思路:
1.分別前序走訪該兩個樹,如果訪問的node是葉子節點就加入List
2.比較兩個List是否相等。
JavaCode: