mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-19 21:31:22 +08:00
38 lines
654 B
Go
38 lines
654 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 isMirror(left *TreeNode, right *TreeNode) bool {
|
|
if left == nil && right == nil {
|
|
return true
|
|
}
|
|
|
|
if left == nil || right == nil {
|
|
return false
|
|
}
|
|
|
|
return (left.Val == right.Val) && isMirror(left.Left, right.Right) && isMirror(left.Right, right.Left)
|
|
}
|
|
|
|
func isSymmetric(root *TreeNode) bool {
|
|
if root == nil {
|
|
return true
|
|
}
|
|
|
|
return isMirror(root.Left, root.Right)
|
|
}
|