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 ...
随机推荐
- 提示框插件SweetAlert
SweetAlert可以替代Javascript原生的alert和confirm等函数呈现的弹出提示框, 它将提示框进行了美化,并且允许自定义, 支持设置提示框标题.提示类型.内容展示图片.确认取消按 ...
- asp.net 总结
asp.net 是服务器段控件,运行是返回一个客户端html 页面给服务器
- 从头开始-04.C语言中流程控制
分支结构: if语句:当条表达式满足的时候就执行if后面大括号中语句 三种格式: if,if else , if else if else 特点:1.只有一个代码块会被执行 2.若有else那么必有一 ...
- JQ调用后台方法
首先,先在页面上创建一个asp按钮,添加点击事件,把要在前台调用的后台方法写在这个按钮的点击事件中: <span style="display:none;"><a ...
- asp.net uploadfile 上传文件,连接已重置问题
修改web.config中的配置 <httpRuntime maxRequestLength="/> //设置上传文件大小(kb)和响应时间(s) 针对iis7或更高版本另需要在 ...
- 04JS高级动态添加属性和删除属性
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- windows 安装paramiko模块
首先需要安装pycrypto这个模块,这个下源码编译安装的不能用报错warning: GMP or MPIR library not found; Not building这个用编译好的模块安装已编译 ...
- 开发环境配置--Ubuntu+Qt4+OpenCV(三)
同系列文章 1. 开发环境配置--Ubuntu+Qt4+OpenCV(一) 2. 开发环境配置--Ubuntu+Qt4+OpenCV(二) 3. 开发环境配置--Ubuntu+Qt4+OpenCV(三 ...
- (转)对mysql explain讲的比较清楚的
转自:http://www.blogjava.net/persister/archive/2008/10/27/236813.html 在 explain的帮助下,您就知道什么时候该给表添加索引,以使 ...
- View的事件分发机制
一.点击事件的传递规则 传递事件的主要方法: public boolean dispatchTouchEvent(MotionEvent ev) 如果事件能够传递到当前View,则该方法一定会被调用. ...