Skip to content

Commit 7aa0f81

Browse files
committed
等价二叉树
1 parent fe329c1 commit 7aa0f81

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

identical_binary_tree.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
"""
5+
@param a, b, the root of binary trees.
6+
@return true if they are identical, or false.
7+
"""
8+
def isIdentical(self, a, b):
9+
# Write your code here
10+
if not (a or b):
11+
return True
12+
if a and b:
13+
if a.val == b.val:
14+
return self.isIdentical(a.left, b.left) and self.isIdentical(a.right, b.right)
15+
return False

0 commit comments

Comments
 (0)