标签:
题目:
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)
标签:
原文地址:http://www.cnblogs.com/def-ly/p/5398321.html