u
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package top100liked
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// https://leetcode.cn/problems/symmetric-tree/description/?envType=study-plan-v2&envId=top-100-liked
|
||||
|
||||
type TreeNode struct {
|
||||
Val int
|
||||
Left *TreeNode
|
||||
Right *TreeNode
|
||||
}
|
||||
|
||||
func isSymmetric(root *TreeNode) bool {
|
||||
return check(root.Left, root.Right)
|
||||
}
|
||||
|
||||
func check(p, q *TreeNode) bool {
|
||||
if p == nil && q == nil {
|
||||
return true
|
||||
}
|
||||
if p == nil || q == nil {
|
||||
return false
|
||||
}
|
||||
return p.Val == q.Val && check(p.Left, q.Right) && check(p.Right, q.Left)
|
||||
}
|
||||
|
||||
func Test1(t *testing.T) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user