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
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public boolean isSymmetric(TreeNode root) {
return isSymmetric(root,root);
}
public boolean isSymmetric(TreeNode t1,TreeNode t2) {
if(t1==null && t2==null) return true;
if(t1==null || t2==null) return false;
return(t1.val==t2.val && isSymmetric(t1.left,t2.right) && isSymmetric(t1.right,t2.left));
}
}

  

(Tree) 101. Symmetric Tree的更多相关文章

  1. [leetcode tree]101. Symmetric Tree

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

  2. [leetcode] 101. Symmetric Tree 对称树

    题目大意 #!/usr/bin/env python # coding=utf-8 # Date: 2018-08-30 """ https://leetcode.com ...

  3. <LeetCode OJ> 101. Symmetric Tree

    101. Symmetric Tree My Submissions Question Total Accepted: 90196 Total Submissions: 273390 Difficul ...

  4. Leetcode之101. Symmetric Tree Easy

    Leetcode 101. Symmetric Tree Easy Given a binary tree, check whether it is a mirror of itself (ie, s ...

  5. leetcode 100. Same Tree、101. Symmetric Tree

    100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...

  6. Leetcode 笔记 101 - Symmetric Tree

    题目链接:Symmetric Tree | LeetCode OJ Given a binary tree, check whether it is a mirror of itself (ie, s ...

  7. 101. Symmetric Tree

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

  8. 【LeetCode】101 - Symmetric Tree

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

  9. Java [Leetcode 101]Symmetric Tree

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

随机推荐

  1. windows下Bullet 2.82编译安装(Bullet Physics开发环境配置)

    平台:Win7,VS2010 1. Bullet库的组织 下图是Bullet_User_Manual中的截图: 从中可见,Bullet的LinearMath(线性数学模块),其上是BulletColl ...

  2. springmvc学习笔记--ueditor和springmvc的集成

    前言: 在web开发中, 富文本的编辑器真心很重要. 有电商店铺的打理, 新闻稿/博客文章/论坛帖子的编辑等等, 这种所见即所的编辑方式, 大大方便了非技术人员从事互利网相关的工作. 因为手头有个小项 ...

  3. CCI4.4/LintCode Balanced Binary Tree, Binary Tree, Binary Search Tree

    Binary Tree: 0到2个子节点; Binary Search Tree: 所有左边的子节点 < node自身 < 所有右边的子节点: 1. Full类型: 除最下面一层外, 每一 ...

  4. jQuery中$.fn的用法示例介绍

    $.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效,下面有个不错的示例,喜欢的朋友可以参考下 如扩展$.fn.abc(),即$.fn.abc()是对jquery ...

  5. Android使用AudioTrack发送红外信号

    最近要做一个项目,利用手机的耳机口输出红外信号,从而把手机变成红外遥控器,信号处理的知识基本都还给老师了,刚开始真的挺头疼.找了不少资料研究了一下,总算有点心得,在这里做个备忘. 一.音频信号输出原理 ...

  6. 使用jquery、ajax不刷新页面打印表格(返回数据类型text、json);

    效果图: 一:返回数据是text时 1.表单代码: <body> <form action="#" method="post"> 姓名: ...

  7. 前端JavaScript规范

    前端JavaScript规范 http://www.imooc.com/article/1402 http://greengerong.com/blog/2015/05/09/qian-duan-ja ...

  8. 安装恢复Windows10各种坑

    1.安装Windows10最好用微软原装ISO,其它的第三方坑比较多,要么不支持UEFI,要么不支持MBR,要么不支持GPT. 2.恢复系统可以使用WIM备份,或Window原生备份,或者Ghost备 ...

  9. shell脚本,防止sshd被暴力破解

    1.tail -f /var/log/secure 你会发现有很多的登录 错误.这说明你的机器正在被暴力破解. 2.新建 一个 shell脚 本 保存退出. 3.加入定时crontab -e 我这里每 ...

  10. geohash基本原理

    geohash基本原理是将地球理解为一个二维平面,将平面递归分解成更小的子块,每个子块在一定经纬度范围内拥有相同的编码,这种方式简单粗暴,可以满足对小规模的数据进行经纬度的检索 目录: 经纬度常识 认 ...