给定一个二叉树,看它是不是“镜像树”(瞎起的)。

递归。从上往下,分别判断左右子树的根节点值是否相等,相等则继续往下递归,不等则返回False。

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = Noneclass Solution:def isSymmetric(self, root):""":type root: TreeNode:rtype: bool"""if not root:return Truereturn self.helper(root.left, root.right)def helper(self, root1, root2):if not root1 and not root2:return Trueelif not root1 or not root2:return Falseelif root1.val != root2.val:return Falsereturn self.helper(root1.left, root2.right) and self.helper(root1.right, root2.left)

16/100. Symmetric Tree相关推荐

  1. 101. Symmetric Tree (C语言)

    101. Symmetric Tree (C语言) 判断是否为左右镜面对称的二叉树 题目 Given the root of a binary tree, check whether it is a ...

  2. 【LeetCode 剑指offer刷题】树题6:28 对称二叉树(101. Symmetric Tree)

    [LeetCode & 剑指offer 刷题笔记]目录(持续更新中...) 101. Symmetric Tree /**  * Definition for a binary tree no ...

  3. 【LeetCode从零单排】No100 Same Tree No101 Symmetric Tree

    题目 1.same tree Given two binary trees, write a function to check if they are equal or not. Two binar ...

  4. Symmetric Tree (101)

    Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ...

  5. LeetCode 100. Same Tree

    LeetCode 100. Same Tree Solution1: 这种弱智题提交这么多次... /*** Definition for a binary tree node.* struct Tr ...

  6. LeetCode 101. Symmetric Tree

    LeetCode 101. Symmetric Tree Solution1 参考<剑指offer>上的解法:https://blog.csdn.net/allenlzcoder/arti ...

  7. 为什么连接xshell报错Could not connect to 172.16.16.100 (port 22): Connection failed

    连接xshell报错Could not connect to '172.16.16.100' (port 22): Connection failed. 今天小编也遇到了这个问题开启虚拟机连接xshe ...

  8. Leetcode: 101. Symmetric Tree

    题目 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). Fo ...

  9. [Leetcode]100. Same Tree -David_Lin

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

最新文章

  1. “掘金”金融AI落地,英特尔趟出一套通关攻略
  2. oracle 延迟段,oracle - 未启用延迟段创建功能(ORA-00439) - 堆栈内存溢出
  3. orcle 删除表报正在使用_ORA-14452:试图创建,更改或删除正在使用的临时表中的索引...
  4. MBR和GPT概要学习
  5. 由文档那些事儿引发的思考 - 领导,您该反思了
  6. mac地址厂商对应表_网络工程师一分钟搞懂MAC地址表知识点全部内容,建议收藏...
  7. 《数据结构上机实验(C语言实现)》笔记(2 / 12):线性表
  8. docker知识总结
  9. 心得7--JDBC回顾-批处理案例解说
  10. 线性插值改变图像尺寸_图像分割--gt;上采样的那些事
  11. 哔哩哔哩助手 for Mac说明书
  12. D触发器、D上升沿触发器、T触发器
  13. Could not load org.apache.hadoop.hive.conf.HiveConf. Make sure HIVE_CONF_DIR is set correctly.
  14. 微信浪漫告白小程序java_微信表白小程序有哪些?微信小程序520表白神器推荐...
  15. AUTOSAR MCAL详解:FLS
  16. 手机测试相关基础知识
  17. 计算机excel操作教程,Excel操作教程 -电脑资料
  18. pikachu-sql注入(皮卡丘)
  19. XAG的真实性以及投资价值
  20. 人在年轻的时候,最核心的能力是什么?

热门文章

  1. 复制linux内核,linux内核写时复制机制源代码解读
  2. python如何实现matlab_Python实现matlab数据绘制
  3. java2ee和java2se_Java知识:(2)JavaSE和JavaEE
  4. java抽象工厂设计模式_23种经典设计模式的java实现_1_抽象工厂模式
  5. atan java_Java atan() 方法
  6. android support design library eclipse,Eclipse下使用Android Design Support Library中的控件
  7. python正则表达式知识点
  8. inline-block清除空隙2
  9. router vue 多个路径_多个vue子路由文件自动化合并的方法,
  10. java并发面试题(一)基础