leetcode 判斷是否子樹subtree-of-another-tree

給定兩個非空二叉樹 s 和 t,檢驗 s 中是否包含和 t 具有相同結構和節點值的子樹

示例 1:

給定的樹 s:

3/ \4 5/ \1 2

給定的樹 t:

4/ \1 2

返回 true,因為 t 與 s 的一個子樹擁有相同的結構和節點值。

我的思路

1 遍歷s

2 在遍歷s過程中判斷是否等於t 知道

4 不然 繼續遍歷s

異常測試

輸入:

[1] [0]

leetcode 判斷是否子樹subtree-of-another-tree

leetcode 判斷是否子樹subtree-of-another-tree

go

leetcode 判斷是否子樹subtree-of-another-tree

c++


分享到:


相關文章: