首页 > 编程语言 > 详细

Leetcode 100 Same Tree python

时间:2016-04-16 15:14:26      阅读:234      评论:0      收藏:0      [点我收藏+]

题目:

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.

 

 1 class Solution(object):
 2     def isSameTree(self, p, q):
 3         if p == None and q == None:
 4             return True
 5         elif p == None and q != None:
 6             return False
 7         elif p != None and q == None:
 8             return False
 9         elif p.val != q.val:
10             return False
11         elif p.val == q.val:
12             return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)

 

Leetcode 100 Same Tree python

原文:http://www.cnblogs.com/def-ly/p/5398321.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!