LintCode Q469 Identical Binary Tree in Python

  • Jinhai ZHOU
  • 2 Minutes
  • 2016年11月30日
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""
Definition of TreeNode:
class TreeNode:
def __init__(self, val):
this.val = val
this.left, this.right = None, None
"""
class Solution:
"""
@param a, b, the root of binary trees.
@return true if they are identical, or false.
"""
def isIdentical(self, a, b):
# Write your code here
if a is None and b is None:
return True
elif a and b and a.val == b.val:
return self.isIdentical(a.left, b.left) and self.isIdentical(a.right, b.right)
else:
return False
知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。