#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 ...
随机推荐
- maven项目文件乱码问题
今日碰到maven项目中的一个资源文件出现乱码,排查发现是在.setting文件夹下的org.eclipse.core.resources.prefs文件导致的. 修改前的编码规则如下: <sp ...
- GitHub简历
My GitHub Résumé可以帮你生成一份github简历,你只需要输入你的github用户名.
- SAP ABAP 程序调用FORM
*&---------------------------------------------------------------------* *& Report ZHAIM_FOR ...
- msvcp110.dll丢失
方法1:建议下载并安装[百度电脑专家],在搜索框内输入“vs2012运行时库缺失”,在搜索结果里面选择[立即修复],修复完成后验证是否正常: 方法2:手动修复 2.1 在[百度]下载“msvcp110 ...
- c pointer and array
Pointer: A pointer is a variable that contains the address of a variable. if c is a char and p is a ...
- Android-打反编译工具的一种方法
转载请注明出处:http://blog.csdn.net/goldenfish1919/article/details/41010261 首先我们来看下dex文件的格式: class_defs的结构: ...
- Glossary of Terms in the JavaTM platform --reference
http://docs.oracle.com/javase/tutorial/information/glossary.html field :A data member of a class. Un ...
- atlassian-jira-confluence-bitbucket破解
==================================================================================================== ...
- java String的比较,BOX装箱拆箱,以及面向对象的小代码
package cn.hncu.day2; public class StringDemo { public static void main(String[] args) { String str1 ...
- [Eclipse]The type XXX cannot be resolved. It is indirectly referenced from required .class files
在Eclipse中遇到The type XXX cannot be resolved. It is indirectly referenced from required .class files错误 ...