【easy】100. Same 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 isSameTree(TreeNode* p, TreeNode* q) {
if ((p==NULL&&q!=NULL)||(q==NULL&&p!=NULL)) return false;
if (p==NULL && q==NULL) return true; if (p->val != q->val) return false;
else return isSameTree(p->left,q->left)&&isSameTree(p->right,q->right);
/*
if (p->left != NULL && q->left != NULL){
if (p->left->val != q->left->val) return false;
isSameTree(p->left,q->left);
}
if (p->right != NULL && q->right != NULL){
if (p->right->val != q->right->val) return false;
isSameTree(p->right,q->right);
}
//一个大错特错的递归…………
*/
//return true;
}
};
【easy】100. Same Tree的更多相关文章
- 【LeetCode】100. Same Tree 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 [LeetCode] 题目地址:https:/ ...
- 【LeetCode】100 - Same Tree
Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...
- 【easy】257. Binary Tree Paths 二叉树找到所有路径
http://blog.csdn.net/crazy1235/article/details/51474128 花样做二叉树的题……居然还是不会么…… /** * Definition for a b ...
- 【easy】107. Binary Tree Level Order Traversal II 按层输出二叉树
按层输出二叉树,广度优先. 3 / \ 9 20 / \ 15 7 [ [15,7], [9,20], [3] ] /** * Definition for a binary tree node. * ...
- 【easy】101. Symmetric Tree
判断一棵二叉树是否对称 /** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left ...
- 【LeetCode】100. Same Tree (2 solutions)
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- 【Leetcode】【Easy】Balanced Binary Tree
Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary ...
- 606. Construct String from Binary Tree 【easy】
606. Construct String from Binary Tree [easy] You need to construct a string consists of parenthesis ...
- 【数据结构】B-Tree, B+Tree, B*树介绍 转
[数据结构]B-Tree, B+Tree, B*树介绍 [摘要] 最近在看Mysql的存储引擎中索引的优化,神马是索引,支持啥索引.全是浮云,目前Mysql的MyISAM和InnoDB都支持B-Tre ...
随机推荐
- 如何卸载VS 2017之前版本比如VS 2013、VS2015、 VS vNext?
前言 大学专业为软件工程,进入大学之后才知道这个专业需要用到笔记本,我的笔记本配置为I3,内存4个G,已经有大几年了,中间坏了修了一次一直用到现在,这个笔记本还是我哥打工过年回来身上仅有的三四千块钱所 ...
- vagrant之常用操作
基本操作: 查看版本: vagrant -v 初始化: vagrant init 启动虚拟机: vagrant up 关闭虚拟机: vagrant halt 重启虚拟机: vagrant reload ...
- svn 服务器部署
系统环境:CentOS 7.x安装方式:yum install (源码安装容易产生版本兼容的问题)安装软件:系统自动下载SVN软件 #检查是否安装了低版本的SVN[root@localhost /]# ...
- sql 书写 规范 优化
规范 做注解 便于修改和优化 规范 <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE map ...
- Python学习之路——装饰器
开放封闭原则:不改变调用方式与源代码上增加功能 ''' 1.不能修改被装饰对象(函数)的源代码(封闭) 2.不能更改被修饰对象(函数)的调用方式,且能达到增加功能的效果(开放) ''' 装饰器 # 把 ...
- input按钮使用方法
- Spring MVC 使用介绍(五)—— 注解式控制器(一):基本介绍
一.hello world 相对于基于Controller接口的方式,基于注解方式的配置步骤如下: HandlerMapping 与HandlerAdapter 分别配置为RequestMapping ...
- MAGENTO for XAMPP install config -搬家配置与安装配置
MEGENTO . 2.2.3 . 支持 PHP version is 7.0.2|7.0.4|~7.0.6|~7.1.0 虚拟机主机配置 环境扩展配置 其他错误 httpd-conf —— ...
- luogu4770 [NOI2018]你的名字 (SAM+主席树)
对S建SAM,拿着T在上面跑 跑的时候不仅无法转移要跳parent,转移过去不在范围内也要跳parent(注意因为范围和长度有关,跳的时候应该把长度一点一点地缩) 这样就能得到对于T的每个前缀,它最长 ...
- bzoj5028小Z的加油店(线段树+差分)
题意:维护支持以下两种操作的序列:1 l r询问a[l...r]的gcd,2 l r x把a[l...r]全部+x 题解:一道经典题.根据gcd(a,b)=gcd(a-b,b)以及区间加可知,这题可以 ...