天天看點

leetcode Same Tree python

# Definition for a binary tree node.
# class TreeNode(object):
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution(object):
    def isSameTree(self, p, q):
        """
        :type p: TreeNode
        :type q: TreeNode
        :rtype: bool
        """
        if p == None and q == None:
            return True
        if p and q and p.val == q.val:
            return self.isSameTree(p.right,q.right) and self.isSameTree(p.left,q.left)
        return False      

轉載于:https://www.cnblogs.com/allenhaozi/p/5024652.html