mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-05 00:25:22 +08:00
31 lines
534 B
Go
31 lines
534 B
Go
package leetcode
|
|
|
|
import (
|
|
"github.com/halfrost/LeetCode-Go/structures"
|
|
)
|
|
|
|
// TreeNode define
|
|
type TreeNode = structures.TreeNode
|
|
|
|
/**
|
|
* Definition for a binary tree node.
|
|
* type TreeNode struct {
|
|
* Val int
|
|
* Left *TreeNode
|
|
* Right *TreeNode
|
|
* }
|
|
*/
|
|
|
|
func isSameTree(p *TreeNode, q *TreeNode) bool {
|
|
if p == nil && q == nil {
|
|
return true
|
|
} else if p != nil && q != nil {
|
|
if p.Val != q.Val {
|
|
return false
|
|
}
|
|
return isSameTree(p.Left, q.Left) && isSameTree(p.Right, q.Right)
|
|
} else {
|
|
return false
|
|
}
|
|
}
|