码迷,mamicode.com
首页 > 编程语言 > 详细

Leetcode 100 Same Tree python

时间:2016-04-16 15:16:17      阅读:195      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!