牛客题霸 NC16 判断二叉树是否对称
生活随笔
收集整理的這篇文章主要介紹了
牛客题霸 NC16 判断二叉树是否对称
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://www.nowcoder.com/practice/1b0b7f371eae4204bc4a7570c84c2de1
解決方案
Go
func isSymmetric(root *TreeNode) bool {// write code hereif root == nil {return true}return symmetric(root.Left, root.Right) } func symmetric(a, b *TreeNode) bool {if a == nil && b == nil {return true}if a != nil && b != nil {return a.Val == b.Val && symmetric(a.Left, b.Right) && symmetric(a.Right, b.Left)}return false }參考文章
總結
以上是生活随笔為你收集整理的牛客题霸 NC16 判断二叉树是否对称的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 牛客题霸 NC15 求二叉树的层序遍历
- 下一篇: 牛客题霸 NC17 最长回文子串