题解 | #判断二叉树是否相等#
判断二叉树是否相等
http://www.nowcoder.com/practice/9a9e74b71f944efab9992925f7f9a65e
gogogo
双树为空————true
单树为空————false
双树非空:递归判断
广度优先请看: 链接
深度优先:
func isSameTree( p *TreeNode , q *TreeNode ) bool {
// write code here
if p == nil && q == nil{
return true
}else if p == nil || q == nil{
return false
}else if p.Val == q.Val{
return isSameTree(p.Left,q.Left) && isSameTree(p.Right,q.Right)
}else{
return false
}
}