https://leetcode.com/problems/symmetric-tree/

    1. /**
    2. * Definition for a binary tree node.
    3. * type TreeNode struct {
    4. * Val int
    5. * Left *TreeNode
    6. * Right *TreeNode
    7. * }
    8. */
    9. func isSymmetric(root *TreeNode) bool {
    10. if root == nil {
    11. return true
    12. }
    13. return isSymmetricTrack(root.Left, root.Right)
    14. }
    15. func isSymmetricTrack(p *TreeNode, q *TreeNode) bool{
    16. if p == nil && q == nil {
    17. return true
    18. }
    19. if p == nil || q == nil {
    20. return false
    21. }
    22. return (p.Val == q.Val) && isSymmetricTrack(p.Left, q.Right) && isSymmetricTrack(p.Right, q.Left)
    23. }