Leetcode - Symmetric Tree
https://leetcode.com/problems/symmetric-tree/
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).
For example, this binary tree [1,2,2,3,4,4,3]
is symmetric:
1 / \ 2 2 / \ / \ 3 4 4 3
/** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func isSymmetric(root *TreeNode) bool { if root == nil { return true } 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) }
Oct 10, 2021 07:40:52 PM
It is unique to see things like this. It is a great scene.
Feb 14, 2022 03:27:43 PM
violet's Blog is a wonderful and amazing blog for readers. Sexy Delhi Escort Hot Delhi Escorts[/url]