100. Same Tree

class Solution {
public:
bool isSameTree(TreeNode* p, TreeNode* q) {
if(p == NULL && q == NULL)
return true;
else if(p == NULL || q == NULL)
return false;
if(p->val != q->val)
return false;
return isSameTree(p->left,q->left) && isSameTree(p->right,q->right);
}
};

101. Symmetric Tree

/**
* 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* root) {
if(!root)
return true;
return isSymmetric(root,root);
}
bool isSymmetric(TreeNode* left,TreeNode* right){
if(!left && !right)
return true;
if(!left || !right)
return false;
if(left->val != right->val)
return false;
return isSymmetric(left->left,right->right) && isSymmetric(left->right,right->left);
}
};

leetcode 100. Same Tree、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 Easy

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

  3. <LeetCode OJ> 101. Symmetric Tree

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

  4. Leetcode 笔记 101 - Symmetric Tree

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

  5. Leetcode 101 Symmetric Tree 二叉树

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

  6. [LeetCode]题解(python):101 Symmetric tree

    题目来源 https://leetcode.com/problems/symmetric-tree/ Given a binary tree, check whether it is a mirror ...

  7. 【LeetCode】101. Symmetric Tree (2 solutions)

    Symmetric Tree Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its ...

  8. 【LeetCode】101. Symmetric Tree 对称二叉树(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 [LeetCode] 题目地址 ...

  9. 【LeetCode】101 - Symmetric Tree

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

随机推荐

  1. Java学习笔记【十一、序列化】

    序列化的条件 实现Serializable接口 所有属性必须是可序列化的,或标记为transient(不做序列化) 序列化-将对象输出为序列化文件 ObjectOutputStream 反序列化-将序 ...

  2. Maxwell平滑升级流程

    1. 同步配置文件 copy之前的配置文件     2  关掉监控程序  如果有的话     3  kill掉之前的maxwell程序     4 查询已经读取到的position位置,然后重启服务 ...

  3. linux网络协议栈--路由流程分析

    转:http://blog.csdn.net/hsly_support/article/details/8797976 来吧,路由 路由是网络的核心,是linux网络协议栈的核心,我们找个入口进去看看 ...

  4. IoT 设备通信安全讨论

    IoT 设备通信安全讨论 作者:360CERT 0x00 序言 IoT 设备日益增多的今天,以及智能家居这一话题愈发火热,智能家居市场正在飞速的壮大和发展,无数 IoT 设备正在从影片中不断的走向用户 ...

  5. NLP/CL 顶会收录

    全文转载自知乎@刘知远老师:初学者如何查阅自然语言处理学术资料(2016修订版). 1. 国际学术组织.学术会议与学术论文 自然语言处理(natural language processing,NLP ...

  6. 延长zencart1.5.x后台的15分钟登录时间和取消90天强制更换密码

    延长zencart1.5.x后台的15分钟登录时间 打开includes\functions\sessions.php if (IS_ADMIN_FLAG === true) { if (!$SESS ...

  7. 【XDOJ】坑爹的杜神

    原题: 众所周知,杜神非常喜欢出大模拟,也非常喜欢设置一些细节坑人.例如,在某次大赛中,他出了一道这样的题 (以下省略3000字) 计算出答案a后,你应该将a除以1000,再保留到小数点后两位输出,四 ...

  8. HTML符号代码速查表

    HTML实体符号被用作实现保留字符(reserved characters)或者表达键盘无法输入的一些常用字符.在大多数浏览器中默认的字符集为ISO-8859-1.HTML实体符号使我们在网页设计中经 ...

  9. hutools之批量更新

    public class HutoolTest { private static DataSource dataSource = DSFactory.get(); //读取默认路径下的配置文件,数据库 ...

  10. 网络资源url转化为file对象下载文件

    注:只测试过网络图片资源. 一.使用org.apache.commons.io.FileUtils 二. 三.httpURLConnection.disconnect(); 四. import org ...