mirror of https://github.com/01-edu/public.git
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.
25 lines
449 B
25 lines
449 B
5 years ago
|
package correct
|
||
5 years ago
|
|
||
|
type TreeNodeL struct {
|
||
5 years ago
|
Left *TreeNodeL
|
||
|
Val int
|
||
|
Right *TreeNodeL
|
||
5 years ago
|
}
|
||
|
|
||
|
func IsSameTree(p *TreeNodeL, q *TreeNodeL) bool {
|
||
5 years ago
|
if p == nil && q == nil {
|
||
|
return true
|
||
|
}
|
||
5 years ago
|
return checkIfEq(p, q)
|
||
5 years ago
|
}
|
||
|
|
||
|
func checkIfEq(t1 *TreeNodeL, t2 *TreeNodeL) bool {
|
||
5 years ago
|
if t1 == nil && t2 == nil {
|
||
|
return true
|
||
|
}
|
||
|
if t1 == nil || t2 == nil {
|
||
|
return false
|
||
|
}
|
||
5 years ago
|
return t1.Val == t2.Val && checkIfEq(t1.Right, t2.Right) && checkIfEq(t1.Left, t2.Left)
|
||
5 years ago
|
}
|