语言: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的更多相关文章

  1. #Leet Code# Binary Tree Max[待精简]

    描述:递归调用,getMax返回 [节点值,经过节点左子节点的最大值,经过节点右节点的最大值],每次递归同时查看是否存在不经过节点的值大于max. 代码:待优化 def getLargeNode(se ...

  2. #Leet Code# Unique Tree

    语言:Python 描述:使用递归实现 class Solution: # @return an integer def numTrees(self, n): : elif n == : else: ...

  3. Code the Tree(图论,树)

    ZOJ Problem Set - 1097 Code the Tree Time Limit: 2 Seconds      Memory Limit: 65536 KB A tree (i.e. ...

  4. poj 2567 Code the Tree 河南第七届省赛

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2350   Accepted: 906 Desc ...

  5. Code the Tree

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2292   Accepted: 878 Description A tree ...

  6. POJ Code the Tree 树的pufer编号

    Code the Tree Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2259   Accepted: 859 Desc ...

  7. 第七届河南省赛G.Code the Tree(拓扑排序+模拟)

    G.Code the Tree Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 18 [Submit][Status][Web ...

  8. 【Leet Code】Palindrome Number

    Palindrome Number Total Accepted: 19369 Total Submissions: 66673My Submissions Determine whether an ...

  9. Leet Code 771.宝石与石头

    Leet Code编程题 希望能从现在开始,有空就做一些题,自己的编程能力太差了. 771 宝石与石头 简单题 应该用集合来做 给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S  ...

随机推荐

  1. javascript中String 对象slice 和substring 区别

      1.slice(start,stop)和substring(start,stop)  方法都是用于提取字符串中从start开始到stop-1间的字符(因为字符串索引是从0开始).其中 start必 ...

  2. 更改Sublimetext3的主题文件,改变某些不喜欢的颜色

    使用的主题是Monokai(SL),主题很好看,但是注释和内容选中的颜色看起来跟没有一个样,看起来很淡,所以稍微改一下主题文件的颜色.

  3. 在java项目中应用ueditor

    虽然百度ueditor的官网和文档都已经很详细了.但是自己还是记录下 自己使用uEditor的过程. 这是 他的官网 http://ueditor.baidu.com/website/  例子 文档什 ...

  4. KALI ssh无法登陆的解决办法

    应该是sshd的设置不允许root用户用密码远程登录 修改 vim /etc/ssh/sshd_config 找到# Authentication:LoginGraceTime 120PermitRo ...

  5. Windows2012中安装域控(DC) + SQL Server 2014 + TFS 2015

    安装域控(DC) 修改计算机名 修改固定IP 添加角色 选择“Role-based or feature-based installation” 选择本机 选择“Active Directory Do ...

  6. Linux自动化运维部署+运维

    自动化部署及配置(Cobbler/Kickstart) 红帽发布的网络安装服务器套件 Cobbler可以说是一大Linux装机利器,可以快速的建立网络安装环境,据说比Kickstart还要好用. 分布 ...

  7. 解析嵌套json字符串,一个json字符串中嵌套另一个json字符串

    我现在有一个字符串是这样: { "msg": { ", "attrName": "sensorData", "trans ...

  8. 定位 position

    html结构是fixed包裹relative,relative包裹absolute position:relative;相对定位 a 不影响元素本身的特性 b 不使元素脱离文档流(元素移动之后原始位置 ...

  9. mvc 路由 使用

    url 特性路由: 特性路由可以在 controller和action里面自定义路由规则  这种方式比较灵活  缺点就是不能很好的统一管理url 注册特性路由: public static void ...

  10. Socket服务器整体架构概述

    转载:http://www.cnblogs.com/tianzhiliang/archive/2010/10/28/1863684.html Socket服务器主要用于提供高效.稳定的数据处理.消息转 ...