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. UVa 10701 - Pre, in and post

    题目:已知树的前根序,中根序遍历转化成后根序遍历. 分析:递归,DS.依据定义递归求解就可以. 前根序:根,左子树,右子树: 中根序:左子树,根,右子树: 每次,找到根.左子树.右子树,然后分别递归左 ...

  2. 配置linux中文

    1.~/.bash_profile文件添加一下内容并执行source  ~/.bash_profile export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK 2./etc ...

  3. 中控考勤机-C#操作

    引用:Interop.zkemkeeper.dll 实例化: public zkemkeeper.CZKEM axCZKEM1 = new zkemkeeper.CZKEM(); 首先从数据库中获取考 ...

  4. return 与 finally

    (function hello() { try { return console.log('return'); } catch (e) { } finally { console.log('final ...

  5. FCKeditor插件开发实例:uploadify多文件上传插件

    FCKeditor是一个专门使用在网页上属于开放源代码的所见即所得文字编辑器.它志于轻量化,不需要太复杂的安装步骤即可使用.它可和PHP.JavaScript.ASP.ASP.NET.ColdFusi ...

  6. POJ1636 动态规划+并查集

    POJ1636 问题重述: 两个监狱中各有m个囚犯,欲对这两个监狱中的囚犯进行等数量的交换.已知某些囚犯不能关押在同一个监狱,求解可以交换人数的最大值k (k < m/2). 分析: 假设监狱1 ...

  7. 判断display为隐藏还是显示及获取css

    <html lang="en"> <head> <title>判断display为隐藏还是显示及获取css</title> < ...

  8. 使用 OpenWrt Image Generator 为 WR703N 路由器定制固件

    标题:使用 OpenWrt Image Generator 为 WR703N 路由器定制固件 之前试着自己编译固件,编译是成功了,但是在后期安装官方仓库的ipk时出现问题,因为自己编译的固件和官方固件 ...

  9. 学习ReactNative笔记整理一___JavaScript基础

    学习ReactNative笔记整理一___JavaScript基础 ★★★笔记时间- 2017-1-9 ★★★ 前言: 现在跨平台是一个趋势,这样可以减少开发和维护的成本.第一次看是看的ReactNa ...

  10. IOS 面试 --- 动画 block

    1 谈谈对Block 的理解?并写出一个使用Block执行UIVew动画? 答案:Block是可以获取其他函数局部变量的匿名函数,其不但方便开发,并且可以大幅提高应用的执行效率(多核心CPU可直接处理 ...