题目:

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.

 class Solution(object):
def isSameTree(self, p, q):
if p == None and q == None:
return True
elif p == None and q != None:
return False
elif p != None and q == None:
return False
elif p.val != q.val:
return False
elif p.val == q.val:
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)

Leetcode 100 Same Tree python的更多相关文章

  1. LeetCode 100. Same Tree (判断树是否完全相同)

    100. Same Tree Given two binary trees, write a function to check if they are the same or not. Two bi ...

  2. leetcode 100. Same Tree、101. Symmetric Tree

    100. Same Tree class Solution { public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL &am ...

  3. [LeetCode] 100. Same Tree 相同树

    Given two binary trees, write a function to check if they are the same or not. Two binary trees are ...

  4. LeetCode 100. Same Tree (相同的树)

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  5. [leetcode]Balanced Binary Tree @ Python

    原题地址:http://oj.leetcode.com/problems/balanced-binary-tree/ 题意:判断一颗二叉树是否是平衡二叉树. 解题思路:在这道题里,平衡二叉树的定义是二 ...

  6. leetcode 100. Same Tree

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  7. leetcode 100 Same Tree ----- java

    Given two binary trees, write a function to check if they are equal or not. Two binary trees are con ...

  8. Java [Leetcode 100]Same Tree

    题目描述: Given two binary trees, write a function to check if they are equal or not. Two binary trees a ...

  9. leetcode Invert Binary Tree python

    # Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = ...

随机推荐

  1. Spring的PropertyPlaceholderConfigurer应用

    Spring 利用PropertyPlaceholderConfigurer占位符 1. PropertyPlaceholderConfigurer是个bean工厂后置处理器的实现,也就是BeanFa ...

  2. LinqToSql增加、修改、删除---(转载)

    LinqToSql ,EF:外键实体的CRD 2011-03-06 21:56:26|  分类: linq |  标签:编程  |字号 订阅           接触LinqTosql是很久的事情了, ...

  3. linux下mysql连接jar包的位置在哪里?

    linux下连接mysql数据库,肯定也会用到驱动jar包. 该jar包应该被置于jdk安装路径下jre文件夹lib目录的ext文件夹下.例如我的JDK安装路径为/usr/java/jdk1.6.0_ ...

  4. jquery.sortable.js源代码解读

    /* * HTML5 Sortable jQuery Plugin * http://farhadi.ir/projects/html5sortable * * Copyright 2012, Ali ...

  5. USB系列之九:基于ASPI的U盘驱动程序

    USB系列之七和之八介绍了ASPI,并通过一些实例说明了基于ASPI的编程方法,本文使用前两篇文章介绍的知识以及以前介绍的有关DOS驱动程序下驱动程序的内容实际完成一个简单的基于ASPI的U盘驱动程序 ...

  6. MFC radio button 绑定变量用法

    我们在对话框中拖动一个radio button控件,然后点击类向导,结果却发现在Member Variables里看不到Radio控件的ID.这是为什么? 2.1 三个Radio Button,ID分 ...

  7. 《how to design programs》12章函数复合

    我们写代码时要学会适应辅助函数.作者提出了一个问题,如何对一个表排序.排序函数读取一个表,产生另一个表.排序函数的合约和用途如下: (sort empty) ;; expected value: em ...

  8. ZOJ2913Bus Pass(BFS+set)

    Bus Pass Time Limit: 5 Seconds      Memory Limit: 32768 KB You travel a lot by bus and the costs of ...

  9. Robot Framework 安装AutoItLibrary

    1. 下载AutoItLibrary-1.1_x64包,http://code.google.com/p/robotframework-autoitlibrary/ 2. 安装pywin32库,htt ...

  10. SqlServer 数据库日志无法收缩处理过程

    今天按常用方法收缩一个测试用的数据库日志,发现没法收缩! dbcc sqlperf(logspace)     USE [dbname] GO ALTER DATABASE [dbname] SET  ...