add new solutions
This commit is contained in:
parent
e1b702657c
commit
59b71480d4
11 changed files with 343 additions and 0 deletions
27
solutions/1/q100/solution.go
Normal file
27
solutions/1/q100/solution.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package q100
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func traverse(p, q *TreeNode) bool {
|
||||
if p == nil && q == nil {
|
||||
return true
|
||||
}
|
||||
if p == nil || q == nil {
|
||||
return false
|
||||
}
|
||||
if p.Val != q.Val {
|
||||
return false
|
||||
}
|
||||
return traverse(p.Left, q.Left) &&
|
||||
traverse(p.Right, q.Right)
|
||||
}
|
||||
|
||||
func isSameTree(p *TreeNode, q *TreeNode) bool {
|
||||
return traverse(p, q)
|
||||
}
|
||||
|
||||
var _ = isSameTree
|
||||
Loading…
Add table
Add a link
Reference in a new issue