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

解题思路:

重载一个isSymmetric判断两棵树是否对称即可,JAVA实现如下:

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

Java for LeetCode 101 Symmetric Tree的更多相关文章

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

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

  2. Leetcode 101 Symmetric Tree 二叉树

    判断一棵树是否自对称 可以回忆我们做过的Leetcode 100 Same Tree 二叉树和Leetcode 226 Invert Binary Tree 二叉树 先可以将左子树进行Invert B ...

  3. leetcode 101 Symmetric Tree ----- java

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

  4. Java [Leetcode 101]Symmetric Tree

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

  5. LeetCode 101. Symmetric Tree (对称树)

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

  6. (二叉树 DFS 递归) leetcode 101. Symmetric Tree

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

  7. LeetCode 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 判断对称树 C++

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

  9. Leetcode 101. Symmetric Tree(easy)

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

随机推荐

  1. oracle查询、删除表中相同的数据

    delete FROM tablename a WHERE rowid > ( SELECT min(rowid) FROM tablename b WHERE b.id = a.id and ...

  2. SilverLight.3-Validation:二、银光验证。TheLabel、TheDescriptionViewer和TheValidationSummary

    ylbtech-SilverLight.3-DataControls_BetterDataFroms:二.银光验证.TheLabel.TheDescriptionViewer和TheValidatio ...

  3. (转)ubuntu/var/log/下各个日志文件

    本文简单介绍ubuntu/var/log/下各个日志文件,方便出现错误的时候查询相应的log   /var/log/alternatives.log-更新替代信息都记录在这个文件中 /var/log/ ...

  4. 常用jar包之commons-digester使用

    常用jar包之commons-digester使用 学习了:https://blog.csdn.net/terryzero/article/details/4332257 注意了, digester. ...

  5. Linux Unix shell 编程指南学习笔记(第四部分)

    第十六章  shell脚本介绍 此章节内容较为简单,跳过. 第十七章   条件測试 test命令 expr命令 test  格式  test  condition     或者  [ conditio ...

  6. poj 3307 Smart Sister 打表解因子生成数问题

    题意: 给i,求由仅以2,3,5,7为因子的数中第i个是多少. 分析: 打表. 代码: //poj 3307 //sep9 #include <iostream> using namesp ...

  7. apue学习笔记(第十四章 高级I/O)

    本章涵盖了从多概念和函数:非阻塞I/O.记录锁.I/O多路转换.异步I/O.readv和writev函数以及存储映射I/O 非阻塞I/O 非阻塞I/O使我们可以发出open.read和write这样的 ...

  8. oracle中字符串类似度函数实測

    转载请注明出处:http://blog.csdn.net/songhfu/article/details/40074795 主要利用:oracle函数-SYS.UTL_MATCH.edit_dista ...

  9. 转:static关键字的总结

    static关键字的总结 C++的static有两种用法:面向过程程序设计中的static和面向对象程序设计中的static.前者应用于普通变量和函数,不涉及类:后者主要说明static在类中的作用. ...

  10. nodejs 简单的备份github代码初版

    传送门:http://www.jianshu.com/p/002efed0d3af 我的代码: const https = require('https'); const fs = require(& ...