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 ...
随机推荐
- 第三章:挖掘SimpleSection.o
1.查看.o目标文件用objdump 命令, 参数“-h"就是把ELF文件的各个段的基本信息打印出来.也可以使用-X打印更多的信息. 段的属性,Size是段的长度,FIle off 是段开始 ...
- huffman 编码
huffman压缩是一种压缩算法,其中经典的部分就是根据字符出现的频率建立huffman树,然后根据huffman树的构建结果标示每个字符.huffman编码也称为前缀编码,就是每个字符的表示形式不是 ...
- golang之interface
一.概述 接口类型是对 "其他类型行为" 的抽象和概况:因为接口类型不会和特定的实现细节绑定在一起:很多面向对象都有类似接口概念,但Golang语言中interface的独特之处在 ...
- CSS备忘-1
CSS 可以通过以下方式添加到HTML中: 内联样式- 在HTML元素中使用"style" 属性 内部样式表 -在HTML文档头部 <head> 区域使用<sty ...
- Java基础笔记-异常总结,包
异常:是对问题的描述,将问题进行对象封装, 异常的体系: Throwable: 1.Error 2.Exception 1.RuntimeException 异常体系的特点: 异常体系中的所有类以及建 ...
- 将 Maven生成的java项目转化为支持 Eclipse IDE的项目
转自: http://www.xuebuyuan.com/1297046.html 将 Maven生成的java项目转化为支持 Eclipse IDE的项目 在前一篇文章中,我们使用maven创建 ...
- 《think in python》学习-9
think in python think in python -9 案例分析:文字游戏 从文本文件中读取文字 作者提供了一个文本文件words.txt 地址 本章后面案例也会用带该文件中的词组 fi ...
- input的样式简介
<input type="text" autocomplete="off" placeholder="" x-webkit-speec ...
- 使用 Oracle Sql plus的一点经验
1 当你输入的语句有错误的时候,不用重新输入语句,直接输入ed就会出现一个文本文档显示之前输入的语句,这样你可以在文本文档里面修改语句,最后点保存. 2 三个set:设置每行显示的记录长度:SE ...
- There is no satiety in study
好不容易考上了硕士.这个时候,才终于明白什么叫做学无止境.用了1周linux,发现需要学习的东西太多了.life is too short to learn c plus plus 果然如此.不过我们 ...