leetcode Same Tree python
# 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
"""
if p == None and q == None:
return True
if p and q and p.val == q.val:
return self.isSameTree(p.right,q.right) and self.isSameTree(p.left,q.left)
return False
leetcode Same Tree python的更多相关文章
- [leetcode]Symmetric Tree @ Python
原题地址:https://oj.leetcode.com/problems/symmetric-tree/ 题意:判断二叉树是否为对称的. Given a binary tree, check whe ...
- LeetCode:Binary Tree Level Order Traversal I II
LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...
- LeetCode: Binary Tree Traversal
LeetCode: Binary Tree Traversal 题目:树的先序和后序. 后序地址:https://oj.leetcode.com/problems/binary-tree-postor ...
- [LeetCode]题解(python):114 Flatten Binary Tree to Linked List
题目来源 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Given a binary tree, flatten ...
- [LeetCode]题解(python):111 Minimum Depth of Binary Tree
题目来源 https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minim ...
- [LeetCode]题解(python):110 Balanced Binary Tree
题目来源 https://leetcode.com/problems/balanced-binary-tree/ Given a binary tree, determine if it is hei ...
- [LeetCode]题解(python):107 Binary Tree Level Order Traversal II
题目来源 https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ Given a binary tree, return ...
- [LeetCode]题解(python):104 Maximum Depth of Binary Tree
题目来源 https://leetcode.com/problems/maximum-depth-of-binary-tree/ Given a binary tree, find its maxim ...
- [LeetCode]题解(python):103 Binary Tree Zigzag Level Order Traversal
题目来源 https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Given a binary tree, re ...
随机推荐
- Server(Iocp)的那些烦恼
自G-Socket0.88版开源以来,得到很多朋友的支持.从1.0版本至2.0之前,内核几乎没有改变,经过多处的应用其稳定性和效率表现是相当不错的.这几年的经验总结成一句话:服务器程序不是有了一个好的 ...
- Oracle 存储过程之通用分页查询
在数据库中书写通用分页存储过程,有利于代码的维护以及执行效率的提升 create or replace procedure Sp_QueryDatePage ( tableName in varcha ...
- C#整理5——break与continue.及数组
一.break与continue.这两个关键字一般放在循环的花括号里面使用.break——结束整个循环.continue——结束本次循环,进入下次循环. break的案例: using System; ...
- DSOframer 微软官方API的查阅方法
不了解 DSOframer 的朋友,可以先参考文章 DSOframer 的简单介绍和资源整理. 大家在使用 DSOframer 时,常常会不知道在哪里查 API 文档,网上的文章都非常零散,很难找到自 ...
- document.createElement()的用法
今天做项目需要做个添加地址栏和前面需要一个按钮,就看到了这篇文章! document.createElement()是在对象中创建一个对象,要与appendChild() 或 insertBefore ...
- [翻译]理解 ASP.NET 5
**原文:http://docs.asp.net/en/latest/conceptual-overview/understanding-aspnet5-apps.html** 英文捉急,花了挺多时间 ...
- Equal 和==比较
Equal 和==比较 ==操作符专门用来比较两个变量的值是否相等,也就是用于比较变量所对应的内存中所存储的数值是否相同,要比较两个基本类型的数据或两个引用变量是否相当,只能用==操作符. 如果一个变 ...
- 解决Linux文档显示中文乱码问题以及编码转换
解决Linux文档显示中文乱码问题以及编码转换 解决Linux文档显示中文乱码问题以及编码转换 使vi支持GBK编码 由于Windows下默认编码是GBK,而linux下的默认编码是UTF-8,所以打 ...
- baidu-fex 精彩文章
7 天打造前端性能监控系统 http://fex.baidu.com/blog/2014/05/build-performance-monitor-in-7-days/ 前端自动化测试探索 http: ...
- 文本导出到pdf文件
程序中数据导出是经常有的需求,今天学习把文本导出到pdf文件.主要是用QPrinter,QPainter TextEditToPdf::TextEditToPdf(QWidget *parent, Q ...