[leetcode tree]100. Same Tree
判断输入的两棵树是不是相同
判断当前root值,左子树和右子树是否相同
####注意最后用的是 is 而不是 ==,因为最后判断p和q是不是None, 应该判断是不是同一个对象
class Solution(object):
def isSameTree(self, p, q):
if p and q:
return self.isSameTree(p.left,q.left) and self.isSameTree(p.right,q.right) and p.val==q.val
return p is q
[leetcode tree]100. Same Tree的更多相关文章
- Leetcode 笔记 100 - Same Tree
		题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ... 
- LeetCode之100. Same Tree
		------------------------------------------ 递归比较即可 AC代码: /** * Definition for a binary tree node. * p ... 
- 【一天一道LeetCode】#100. Same Tree(100题大关)
		一天一道LeetCode 本系列文章已全部上传至我的github,地址:ZeeCoder's Github 欢迎大家关注我的新浪微博,我的新浪微博 欢迎转载,转载请注明出处 (一)题目 Given t ... 
- 【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 ... 
- LeetCode OJ 100. Same Tree
		Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ... 
- 【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 ... 
- 100.Same Tree(E)
		100. same tree 100. Same Tree Given two binary trees, write a function to check if they are the same ... 
- <LeetCode OJ> 100. Same Tree
		100. Same Tree Total Accepted: 100129 Total Submissions: 236623 Difficulty: Easy Given two binary tr ... 
随机推荐
- R4—R版本升级及swirl新产品出炉
			干货一: 经常有很多朋友会遇到这样一个问题:安装R版本使用了很久以后,在使用新packages时,提示这些包是基于更高版本的R构建的,因此,无法使用这些packages,一般的童鞋遇到这类问题可能非常 ... 
- 解决组合排列问题  A (m ,n) m>=n
			转载自http://blog.csdn.net/sunyujia/article/details/4124011 从n个不同元素中任取m(m≤n)个元素,按照一定的顺序排列起来,叫做从n个不同元素中取 ... 
- APScheduler API -- apscheduler.triggers.interval
			apscheduler.triggers.interval API Trigger alias for add_job(): interval class apscheduler.triggers.i ... 
- spring-boog-测试打桩-Mockito
			Mockito用于测试时进行打桩处理:通过它可以指定某个类的某个方法在什么情况下返回什么样的值. 例如:测试 controller时,依赖 service,这个时候就可以假设当调用 service 某 ... 
- JDk1.8源码StringBuffer
			一.概念 StringBuffer A thread-safe, mutable sequence of characters. A string buffer is like a {@link St ... 
- 建立ARM交叉编译环境 (arm-none-linux-gnueabi-gcc with EABI)【转】
			转自:http://lib.csdn.net/article/embeddeddevelopment/60172?knId=886 建立ARM交叉编译环境 (arm-none-linux-gnueab ... 
- SpringCloud常用注解
			一 @EnableDiscoveryClient,@EnableEurekaClient的区别 SpringCLoud中的“Discovery Service”有多种实现,比如:eureka, con ... 
- 如何查看页面是否开启了gzip压缩
			1.谷歌浏览器 F12 2.在表头单击鼠标右键 3.如果开启了gzip则显示gzip,没有则是空 
- 读取文件和输入——read 脚本命令
			Linux之read命令使用 read命令: read 命令从标准输入中读取一行,并把输入行的每个字段的值指定给 shell 变量 1)read后面的变量var可以只有一个,也可以有多个,这时如果输入 ... 
- 如何验证一个地址可否使用—— MmIsAddressValid函数分析
			又是一篇内核函数分析的博文,我个人觉得Windows的内核是最好的老师,当你想实现一个功能之前可以看看Windows内核是怎么做的,说不定就有灵感呢:) 首先看下官方的注释说明: /*++ Routi ... 
