Talk is cheap.
func hasSubtree(p1 *TreeNode, p2 *TreeNode) bool {
if p1 == nil || p2 == nil {
return false
}
if isPart(p1, p2) {
return true
}
return hasSubtree(p1.Left, p2) || hasSubtree(p1.Right, p2)
}
func isPart(p1, p2 *TreeNode) bool {
if p2 == nil {
return true
}
if p1 == nil || p1.Val != p2.Val {
return false
}
return isPart(p1.Left, p2.Left) && isPart(p1.Right, p2.Right)
}