Java for LeetCode 101 Symmetric Tree
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的更多相关文章
- [leetcode] 101. Symmetric Tree 对称树
题目大意 #!/usr/bin/env python # coding=utf-8 # Date: 2018-08-30 """ https://leetcode.com ...
- Leetcode 101 Symmetric Tree 二叉树
判断一棵树是否自对称 可以回忆我们做过的Leetcode 100 Same Tree 二叉树和Leetcode 226 Invert Binary Tree 二叉树 先可以将左子树进行Invert B ...
- leetcode 101 Symmetric Tree ----- java
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- Java [Leetcode 101]Symmetric Tree
题目描述: Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). ...
- LeetCode 101. Symmetric Tree (对称树)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- (二叉树 DFS 递归) leetcode 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- LeetCode 101. Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- LeetCode 101. Symmetric Tree 判断对称树 C++
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- Leetcode 101. Symmetric Tree(easy)
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
随机推荐
- 【Java】List转化为数组
List转化为数组的两种方式: 第一种: List<String> list = new ArrayList<>(); String [] arr = list.toArray ...
- C++输入和输出中进制问题
默认下都是十进制 int i, j, k, l; cin>>oct>>i; //输入为八进制数 cin>>hex>>j; //输入为十六进制数 cin& ...
- APNS push server端 SSL3.0 转 TLS (iPhone苹果推送服务)
(转载此文,请说明原文出处) 苹果的官方公布 Update to the Apple Push Notification Service October 22, 2014 The Apple Push ...
- 用户空间和内核空间通讯之【Netlink 中】
原文地址:用户空间和内核空间通讯之[Netlink 中] 作者:wjlkoorey258 今天我们来动手演练一下Netlink的用法,看看它到底是如何实现用户-内核空间的数据通信的.我们依旧是在2.6 ...
- LCD设备驱动程序
LCD是Liquid Crystal Display的简称,也就是经常所说的液晶显示器 LCD能够支持彩色图像的显示和视频的播放,是一种非常重要的输出设备 Framebuffer 是Linux系统 ...
- GIS可视化——聚散图
一.简介 随着计算机的发展,浏览器的不断进步与完善,现今大部分浏览渲染效率有了很大的改善, 但是由于浏览器厂商的不同,浏览器种类繁多,性能不一,并且很多用户还使用着不少老的浏览, 那些如IE6.7等的 ...
- 启动mongodb报错问题
[root@zk-datanode-02 mongodb]# bin/mongod -f config/mongo.cnf &[1] 30549[root@zk-datanode-02 mon ...
- grep 精确匹配
使用grep实现精确过滤的五种方法 (1)当被过滤的内容占据一行时 [root@MySQL scripts]# cat oldboy.log 200 0200 2000 [root@My ...
- kohana nginx的配置
kohana nginx的配置 location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php? kohana_uri=/$1 ...
- Linux测网速
$ wget https://raw.github.com/sivel/speedtest-cli/master/speedtest_cli.py$ chmod a+rx speedtest_cli. ...