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 [1,2,2,3,4,4,3]
is symmetric:
1
/ \
2 2
/ \ / \
3 4 4 3
But the following [1,2,2,null,3,null,3]
is not:
1
/ \
2 2
\ \
3 3
Note:
Bonus points if you could solve it both recursively and iteratively
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
bool isSymmetric(TreeNode *lhs, TreeNode *rhs)
{
if (NULL == lhs&&NULL == rhs)return true;
if (NULL!=lhs&&NULL!=rhs&&lhs->val == rhs->val)
{
return isSymmetric(lhs->right, rhs->left) && isSymmetric(lhs->left, rhs->right);
}
return false;
}
bool isSymmetric(TreeNode* root) {
if (!root)return true;
return isSymmetric(root->left, root->right);
}
};
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 (对称树)
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 ----- 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 判断对称树 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 ...
- [leetcode]101. Symmetric Tree对称树
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
随机推荐
- mongoDB 下载/安装/客户端笔记
1.下载: https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-3.0.3.zip 2.安装 1.解压mongodb-win32-x86 64- ...
- ORALCE 游标简单的实例
--取简单的游标 declare cursor sp is select * from user_tables; myrecord user_tables%ROWTYPE; begin open sp ...
- oracle 行转列的例子
with test as(select '1' bit from dual union select '0' from dual )select replace(sys_connect_by_path ...
- The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
问题描述: 修改一个工具功能为读取excel文件中的数据(xls) 本机(windows server 2003 32位) 调试运行正常,部署到服务器(windows server 2003 64位) ...
- mysqlbinlog快速遍历搜索记录 (转)
目标,开发人员说有个数据莫名其妙添加了,但是不知道是从哪里添加的,而且应用功能里面不应该添加这样的数据,为了查清楚来源,所 以我就准备去binlog里面找了,但是binlog有好几个月的数,我这样一个 ...
- 在数据库查询时解决大量in 关键字的方法
有时候在前台界面需要批量处理一些数据时,经常要用到update table set fields=value where keyid in ('1','2',....) 但如果这个数据量如果超过100 ...
- fiddler Android下https抓包全攻略
fiddler Android下https抓包全攻略 fiddler的http.https的抓包功能非常强大,可非常便捷得对包进行断点跟踪和回放,但是普通的配置对于像招商银行.支付宝.陌陌这样的APP ...
- Jedis编程设计:连接池
Jedis作为redis的最佳客户端,它提供了连接池的特性,"连接池"在通常情况下可以有效的提高应用的通信能力,并且这是一种良好的设计模式.Jedis的连接池设计基于apa ...
- nginx按天切割日志
原文链接:http://www.cnblogs.com/benio/archive/2010/10/13/1849935.html 本文只节选部分内容 Nginx自己没有日志分割的功能,一旦时间过长 ...
- Windows组策略同步问题
每当,我们在域控制器上建立一个组策略的时候,我们很希望它能在线马上同步到所有的客户端上去. 当windows2008的域控上的做法:登录到每台windows客户端然后执行,gpupdate /forc ...