问题叙述性说明:

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

For example, this binary tree is symmetric:

    1/ \2   2/ \ / \
3  4 4  3

But the following is not:

    1/ \2   2\   \3    3

Note:
Bonus points if you could solve it both recursively and iteratively.

confused what "{1,#,2,3}" means?

> read more on how binary tree is serialized on OJ.

代码:

递归方法

public class Symmetric_Tree { //javapublic class TreeNode {int val;TreeNode left;TreeNode right;TreeNode(int x) { val = x; }}//recursivelypublic boolean isSymmetric(TreeNode root) {if(root == null)return true;return isSymmetricTree(root.left, root.right);}public boolean isSymmetricTree(TreeNode left, TreeNode right){if(left == null && right == null)return true;if(left == null || right == null ||left.val != right.val)return false;boolean lr = isSymmetricTree(left.left, right.right);boolean rl = isSymmetricTree(left.right, right.left);return lr && rl;}
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

[leetcode]Symmetric Tree相关推荐

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

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

  2. LeetCode 101. Symmetric Tree

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

  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. [LeetCode] Binary Tree Level Order Traversal 二叉树层次遍历(DFS | BFS)

    目录: 1.Binary Tree Level Order Traversal - 二叉树层次遍历 BFS 2.Binary Tree Level Order Traversal II - 二叉树层次 ...

  5. [LeetCode] Binary Tree Paths - 二叉树基础系列题目

    目录: 1.Binary Tree Paths - 求二叉树路径 2.Same Tree - 判断二叉树相等 3.Symmetric Tree - 判断二叉树对称镜像 Binary Tree Path ...

  6. Symmetric Tree (101)

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

  7. 101. Symmetric Tree (C语言)

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

  8. leetcode python3 简单题101. Symmetric Tree

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百零一题 (1)题目 英文: Given a binary tree, chec ...

  9. Leetcode: 101. Symmetric Tree

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

最新文章

  1. SSM-SpringMVC-30:SpringMVC中InitBinder的骇客级优化
  2. 浏览器User-Agent的详细信息
  3. 第7章 Scrapy突破反爬虫的限制
  4. java常见的异常_Java常见的10个异常
  5. 如何搭建中国电信物联网云平台
  6. 999999999分解质因数
  7. iView组件+Django实现前后端分离上传图片
  8. 江苏省专转本计算机专业大类《计算机基础理论 1.2(二)小节习题答案》
  9. JavaScript原型详解(通俗易懂)
  10. Java怎么弹出cmd命令窗口_怎么在java里打开bat文件,并打开cmd窗口执行,举例一个完整代码。...
  11. VMware vSphere与vCenter许可及价格分析
  12. yesterday is a doog day+margesort到底应该怎么写+quicksort到底应该怎么写啊+冒泡到底应该怎么写+ I am a student
  13. 2022-2028年中国科幻行业竞争现状及投资策略研究报告
  14. 关于秒杀场景的全面分析总结
  15. Julia并行计算笔记(二)
  16. 计算机应用中的过程控制,计算机在过程控制中的应用
  17. 自媒体内容发布要求有哪些?
  18. 阿里取消“P”序列职级显示引热议,网友:P3、P4流下了感动的泪水
  19. 766. 托普利茨矩阵(javascript)766. Toeplitz Matrix
  20. 苹果测试充电速度软件,苹果iPhone8 Plus充电测试:快充真的快吗?

热门文章

  1. 极光推送java服务器端_极光推送服务器端(JAVA)
  2. 修改vscode 窗口字体大小和编辑窗口字体大小
  3. Linux系统初学者的常见问题解决集结
  4. 新手学堂:Linux操作系统的启动步骤说明
  5. OSI网络结构的七层模型与TCP/IP层次模型
  6. 亚马逊自动化仓库事故,机器人失手戳破有毒喷雾,24名工人被送医院
  7. 汉堡王,你不要给我们AI泼脏水
  8. PyTorch更新了:支持Windows,新增零维张量
  9. 2018年13个AI趋势 | CB Insights报告
  10. Facebook发布张量理解库,自动编译高性能机器学习核心