#Leet Code# Same Tree
语言:Python
描述:使用递归实现
# Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None class Solution:
# @param p, a tree node
# @param q, a tree node
# @return a boolean
def isSameTree(self, p, q):
if (p is None and q is None):
return True
elif (p is None and q is not None) or (p is not None and q is None):
return False
else:
if (p.val != q.val):
return False
else:
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
#Leet Code# Same Tree的更多相关文章
- #Leet Code# Binary Tree Max[待精简]
描述:递归调用,getMax返回 [节点值,经过节点左子节点的最大值,经过节点右节点的最大值],每次递归同时查看是否存在不经过节点的值大于max. 代码:待优化 def getLargeNode(se ...
- #Leet Code# Unique Tree
语言:Python 描述:使用递归实现 class Solution: # @return an integer def numTrees(self, n): : elif n == : else: ...
- Code the Tree(图论,树)
ZOJ Problem Set - 1097 Code the Tree Time Limit: 2 Seconds Memory Limit: 65536 KB A tree (i.e. ...
- poj 2567 Code the Tree 河南第七届省赛
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2350 Accepted: 906 Desc ...
- Code the Tree
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2292 Accepted: 878 Description A tree ...
- POJ Code the Tree 树的pufer编号
Code the Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2259 Accepted: 859 Desc ...
- 第七届河南省赛G.Code the Tree(拓扑排序+模拟)
G.Code the Tree Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 18 [Submit][Status][Web ...
- 【Leet Code】Palindrome Number
Palindrome Number Total Accepted: 19369 Total Submissions: 66673My Submissions Determine whether an ...
- Leet Code 771.宝石与石头
Leet Code编程题 希望能从现在开始,有空就做一些题,自己的编程能力太差了. 771 宝石与石头 简单题 应该用集合来做 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S ...
随机推荐
- Freemarker的常用技巧总结
Freemarker的常用技巧总结 Freemarker视频教程 1,截取字符串 有的时候我们在页面中不需要显示那么长的字符串,比如新闻标题,这样用下面的例子就可以自定义显示的长度 < lt. ...
- java转c#代码工具集合
1#:Java语言转换器助手地址:http://www.microsoft.com/en-us/download/details.aspx?id=14349 2#:Octopus的.NET转换器地址: ...
- C++中this指针的使用方法.
this指针仅仅能在一个类的成员函数中调用,它表示当前对象的地址.以下是一个样例: void Date::setMonth( int mn ) { month = mn; // 这三句是等价的 thi ...
- Hadoop的辉煌还能延续多久?
摘要:Hadoop已经成为大数据的代名词.短短几年间,Hadoop从一种边缘技术成为事实上的标准.而另一方面,MapReduce在谷歌已不再显赫.当企业瞩目MapReduce的时候,谷歌好像早已进入到 ...
- [Webpack 2] Grouping vendor files with the Webpack CommonsChunkPlugin
Often, you have dependencies which you rarely change. In these cases, you can leverage the CommonsCh ...
- hadoop错误org.apache.hadoop.yarn.exceptions.YarnException Unauthorized request to start container
错误: 14/04/29 02:45:07 INFO mapreduce.Job: Job job_1398704073313_0021 failed with state FAILED due to ...
- 如何获取Android系统中申请对象的信息
最近一直在做有关内存方面的优化工作,在做优化的过程,除了关注内存的申请量以及GC的情况之外,我们经常需要想方法找出是那些对象占用了大量内存,以及他们是如何导致GC的,这意味着我们需要获取对象申请的信息 ...
- Microsoft Visual Studio Professional 2012 专业版 下载
记录(以下内容来自网络收集): 下载地址: https://www.microsoft.com/zh-cn/download/details.aspx?id=30682 直接iso连接下载址: htt ...
- php yield
php中关于 yield 关键字的介绍[点击查看] <?php function gen_one_to_three() { for ($i = 1; $i <= 3; $i++) { // ...
- Customize the SharePoint 2013 search experience with a Content Enrichment web service
Did you ever wish you had more control over how your content is indexed and presented as search resu ...