# 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的更多相关文章

  1. [leetcode]Symmetric Tree @ Python

    原题地址:https://oj.leetcode.com/problems/symmetric-tree/ 题意:判断二叉树是否为对称的. Given a binary tree, check whe ...

  2. LeetCode:Binary Tree Level Order Traversal I II

    LeetCode:Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of ...

  3. LeetCode: Binary Tree Traversal

    LeetCode: Binary Tree Traversal 题目:树的先序和后序. 后序地址:https://oj.leetcode.com/problems/binary-tree-postor ...

  4. [LeetCode]题解(python):114 Flatten Binary Tree to Linked List

    题目来源 https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Given a binary tree, flatten ...

  5. [LeetCode]题解(python):111 Minimum Depth of Binary Tree

    题目来源 https://leetcode.com/problems/minimum-depth-of-binary-tree/ Given a binary tree, find its minim ...

  6. [LeetCode]题解(python):110 Balanced Binary Tree

    题目来源 https://leetcode.com/problems/balanced-binary-tree/ Given a binary tree, determine if it is hei ...

  7. [LeetCode]题解(python):107 Binary Tree Level Order Traversal II

    题目来源 https://leetcode.com/problems/binary-tree-level-order-traversal-ii/ Given a binary tree, return ...

  8. [LeetCode]题解(python):104 Maximum Depth of Binary Tree

    题目来源 https://leetcode.com/problems/maximum-depth-of-binary-tree/ Given a binary tree, find its maxim ...

  9. [LeetCode]题解(python):103 Binary Tree Zigzag Level Order Traversal

    题目来源 https://leetcode.com/problems/binary-tree-zigzag-level-order-traversal/ Given a binary tree, re ...

随机推荐

  1. 【MFC学习笔记-作业5-小数据库】【单选框,复选框,滚动条,列表框】

    界面已经实现完毕. 要完成的操作就是1.性别分组(2选1) 2.属性勾选 3.年龄通过滚动条调整 4.职称通过下方的列表框选择 5.输入姓名 6.存入左方的列表框 7.当选择左方列表框的人时,可以显示 ...

  2. vsts

     首先要搞清楚啥是VSTS,这对于我们安装配置有基础作用.看看这张组织结构图就一目了然了.Visual Studio Team Suite就是我们常说的VS.NET 2005开发环境,安装包3G左右的 ...

  3. Sublime 学习记录(一) Sublime 的快捷键

    Ctrl + Shift + P : 打开命令面板 Ctrl + P : 搜索项目中的文件 Ctrl + W : 关闭当前打开的文件 Ctrl + G : 跳转到第几行 Ctrl + Shift + ...

  4. Struts2 实现文件上传

    单个文件上传 关于如何创建Struts2项目:Struts2 初体验. 一.创建jsp页面: 注意!要上传文件,表单必须添加 enctype 属性,如下:  enctype="multipa ...

  5. Ucenter整合Thinkphp 双向同步登录退出

    1.整合初步工作: 1,安装Ucenter,完成后添加应用,填写要对接的网站地址 2,api , uc_client目录放置对接项目的根目录 3,通信对接,新建Ucenter组,confi文件填写在u ...

  6. ZOJ 1530 - Find The Multiple

    Given a positive integer n, write a program to find out a nonzero multiple m of n whose decimal repr ...

  7. mysql学习(十一)嵌套查询 排序 分组

    select * from products where id in(select id from cats where name like '%java%');//查找类型中名字中包含java的的商 ...

  8. Web页面在手机上显示过大问题

    网上抄来了,自己也备忘下:增加<meta name="viewport" content="width=device-width, initial-scale=1. ...

  9. php中json_encode中文编码问题

    1 <?php 2 class myClass { 3 public$item1=1; 4 public$item2='中文'; 5 6 function to_json() { 7 //url ...

  10. Android onSaveInstanceState()

    我们知道,由于手机的内存问题,很容易造成切换activity之后上一个activity被回收的情况,虽然我们按下back按键的时候,还是能够回到上一个activity,但是此时我们并不是执行的onRe ...