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

中文:给定一二叉树,检查它是否是它自己的镜像(比如,以中心对称)。

递归:

	public boolean isSymmetric(TreeNode root) {
if(root == null)
return true;
return isSymmetric(root,root);
}
public boolean isSymmetric(TreeNode left,TreeNode right) {
if(left == null && right == null)
return true;
else if(left == null || right == null)
return false;
return left.val == right.val && isSymmetric(left.left,right.right) && isSymmetric(left.right,right.left);
}

LeetCode——Symmetric Tree的更多相关文章

  1. LeetCode: Symmetric Tree 解题报告

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

  2. [LeetCode] Symmetric Tree 判断对称树

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

  3. [leetcode]Symmetric Tree @ Python

    原题地址:https://oj.leetcode.com/problems/symmetric-tree/ 题意:判断二叉树是否为对称的. Given a binary tree, check whe ...

  4. 二叉树系列 - [LeetCode] Symmetric Tree 判断二叉树是否对称,递归和非递归实现

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

  5. [Leetcode] Symmetric tree 对称二叉树

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

  6. Python3解leetcode Symmetric Tree

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

  7. LeetCode() Symmetric Tree

    /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...

  8. leetcode:Symmetric Tree【Python版】

    #error caused by:#1:{} 没有考虑None输入#2:{1,2,2} 没有控制h和t#3:{4,-57,-57,#,67,67,#,#,-97,-97} 没有考虑负号,将s从str变 ...

  9. 【LeetCode】Symmetric Tree 推断一棵树是否是镜像的

    题目:Symmetric Tree <span style="font-size:18px;"><span style="font-size:18px; ...

随机推荐

  1. android 开发随笔 - 开发环境搭建

    1.1 问题: 'tools.jar' seems to be not in Android Studio classpath. Please ensure JAVA_HOME points to J ...

  2. 多路复用I/O epoll()

    epoll 是Linux内核中的一种可扩展IO事件处理机制,最早在 Linux 2.5.44内核中引入,可被用于代替POSIX select 和 poll 系统调用,并且在具有大量应用程序请求时能够获 ...

  3. viewstate加密(转)

    ViewState在客户端展开的时候,默认是Auto,不加密的,如果页面有限制性的表单控件才加密,所以,可以查看,代码如下: byte[] bytes = Convert.FromBase64Stri ...

  4. ListView小坑

    ListView的addHeaderView()和addFooterView()方法需要“Call this before calling setAdapter”,否则崩溃. 但是在KITKAT(ap ...

  5. asp.net获取ip地址的方法

    在ASP中使用 Request.ServerVariables("REMOTE_ADDR") 来取得客户端的IP地址,但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的I ...

  6. poj 3104 二分

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12568   Accepted: 3243 Descripti ...

  7. 用C++写出hanoi

    汉诺塔(港台:河內塔)是根据一个传说形成的數學问题有三根杆子A,B,C.A杆上有N个(N>1)穿孔圆盘,盘的尺寸由下到上依次变小.要求按下列规则将所有圆盘移至C杆:-每次只能移动一个圆盘-大的盘 ...

  8. Cocos2d-x 3.0 场景切换

    场景切换要用到导演类Director,一般有两种方式,大多数是用替换场景(replaceScene),也可以用进栈(pushScene)出栈(popScene)的方式进行场景的替换. 场景切换代码: ...

  9. PHP 读取EXCEL

    PHPExcel 自己下载. PHP读取EXCEL public function import_Excel($file_name){ include_once LIB_ROOT_PATH." ...

  10. python 杂记

    class TestA(object): def __init__(self): print("A is initing"); def foo(self): print(" ...