mirror of
https://gitlab.com/mfocko/LeetCode.git
synced 2024-11-10 00:09:06 +01:00
24 lines
406 B
Go
24 lines
406 B
Go
|
package same_tree
|
||
|
|
||
|
/**
|
||
|
* Definition for a binary tree node.
|
||
|
* type TreeNode struct {
|
||
|
* Val int
|
||
|
* Left *TreeNode
|
||
|
* Right *TreeNode
|
||
|
* }
|
||
|
*/
|
||
|
func isSameTree(p *TreeNode, q *TreeNode) bool {
|
||
|
// at least one is nil
|
||
|
if p == nil || q == nil {
|
||
|
return p == q
|
||
|
}
|
||
|
|
||
|
// different values
|
||
|
if p.Val != q.Val {
|
||
|
return false
|
||
|
}
|
||
|
|
||
|
return isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right)
|
||
|
}
|