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. SPI机制

    Service Provider Interface 是java的服务提供的发现机制,很多框架中都有用到. 使用这个机制需要做以下几步: 1,在calsspath下见一个目录:META-INF\ser ...

  2. JS函数的上下文环境

    var i=1; var fn1=function(){ console.log(i); } var fn2=function(){ var i=2; fn1(); } fn2();      // ...

  3. python unicode 和 str 类型的关系

    python (2.X)在进行 运行时候字符串运算的时候, 分为两种类型 str, unicode 前者是 二进制的形式进行对字符串的保存, 后者是 以unicode的方式进行保存, 一般的工作方式为 ...

  4. Android studio 菜单介绍 3.1.文件(File)

    文件(File) 3.1.1.New 1. Android Studio中的Project相当于Eclipse中的Workspace 3.1.5.Close Prject 关闭当前项目打开的窗口 2. ...

  5. Html菜鸡大杂烩

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  6. fastjson解析json,model字段有顺序要求吗

    解决办法已经写到我的公众号,二维码在下面,欢迎关注,谢谢. 本人联系方式: 更多精彩分享,可关注我的微信公众号: 若想给予我分享更多知识的动力,请扫描下面的微信打赏二维码,谢谢!: 微信号:Weixi ...

  7. centos 6 cglib

    Error: Package: glibc-2.12-1.166.el6_7.3.i686 (@ultra-centos-6.7-updates) Requires: glibc-common = 2 ...

  8. 如何修改WAMP中mysql默认空密码

      WAMP安装好后,mysql密码是为空的,那么要如何修改呢?其实很简单,通过几条指令就行了,下面我就一步步来操作. 首先,通过WAMP打开mysql控制台. 提示输入密码,因为现在是空,所以直接按 ...

  9. jQuery 语法

    通过 jQuery,您可以选取(查询,query) HTML 元素,并对它们执行"操作"(actions). jQuery 语法实例 $(this).hide() 演示 jQuer ...

  10. 【jq】c#零基础学习之路(3)继承和虚方法

    c#只能继承一个基类和多个接口(0+) 父类:Human: class Human { public virtual Move() { Console.WriteLine("Human的虚方 ...