添加新题目
This commit is contained in:
26
二叉树/对称二叉树/main.go
Normal file
26
二叉树/对称二叉树/main.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func isSymmetric(root *TreeNode) bool {
|
||||
return checkifq(root.Left, root.Right)
|
||||
}
|
||||
|
||||
func checkifq(a, b *TreeNode) bool {
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
}
|
||||
if a == nil || b == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
return a.Val == b.Val && checkifq(a.Left, b.Right) && checkifq(a.Right, b.Left)
|
||||
}
|
||||
Reference in New Issue
Block a user