(p *TreeNode, q *TreeNode)
| 3 | import . "github.com/austingebauer/go-leetcode/structures" |
| 4 | |
| 5 | func isSameTree(p *TreeNode, q *TreeNode) bool { |
| 6 | // if p is nil and q is not or vice versa |
| 7 | if (p == nil && q != nil) || (p != nil && q == nil) { |
| 8 | return false |
| 9 | } |
| 10 | |
| 11 | // p and q are either both nil or both not nil |
| 12 | if p == nil && q == nil { |
| 13 | return true |
| 14 | } |
| 15 | |
| 16 | // p and q are both not nil |
| 17 | return p.Val == q.Val && |
| 18 | isSameTree(p.Right, q.Right) && |
| 19 | isSameTree(p.Left, q.Left) |
| 20 | } |
no outgoing calls