You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

24 lines
449 B

package correct
type TreeNodeL struct {
Left *TreeNodeL
Val int
Right *TreeNodeL
}
func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool {
if p == nil && q == nil {
return true
}
return checkIfEq(p, q)
}
func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool {
if t1 == nil && t2 == nil {
return true
}
if t1 == nil || t2 == nil {
return false
}
return t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)
}