leetcode100:相同的树

由于二叉树的知识点还不懂,我先借鉴了大佬的代码。后期我会看看二叉树原理的

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

先这样吧,后期补知识点

猜你喜欢

转载自blog.csdn.net/weixin_43160613/article/details/83050093