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++


分享到:


相關文章: