100. Same Tree
2015-12-23 11:28
330 查看
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def isSameTree(self, p, q): """ :type p: TreeNode :type q: TreeNode :rtype: bool """ def same(a,b): f=False if a==None and b==None: return True else: if a==None or b==None: return False else: if a.val==b.val: f=True return f and same(a.left,b.left) and same(a.right,b.right) return same(p,q)
相关文章推荐
- 如何把Win7系统桌面上的内容保存在非系统盘
- 天声人語 20151223 戦後70年のひもじさ
- Win10开发:ListView实现分组和索引
- 在线加密解密很好的一个网站
- iOS 网络访问安全问题解决方法App Transport Security policy requires the use of a secure connection
- ubuntu14.04下nginx+gunicorn部署django1.8
- Unity3D 中 用quaternion 来对一个坐标点进行旋转的初步体会
- oracle怎么处理父子关系(递归查询因子化)
- Android Linux下的常用命令行
- 使用匿名管道在进程间通信 (System.IO.Pipes使用)(转)
- input file控件限制上传文件类型
- iis 配置 aspnet起始页
- linux配置jira的步骤
- Java使用7Zip完成文件的压缩和解压缩
- ECSHOP出现Warning: file_put_contents问题
- github第三方 ios客户端比较推荐:iOctocat? CodeHub?NapCat?
- Android之层次layer-list属性
- 阿里云Docker镜像库
- FireFox背景颜色设置
- 优秀的界面设计技巧