leetcode100 相同的树

class Solution:
    def isSameTree(self, p, q):
        """
        :type p: TreeNode
        :type q: TreeNode
        :rtype: bool
        """
        if p is None:
            return q == None
        if p is not None and q is None:
            return False
        if p.val == q.val:               // 如果连这个都保证不了, 那就不要谈了
            return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)
        else:
            return False

猜你喜欢

转载自blog.csdn.net/weixin_36149892/article/details/80516871