100. Same Tree

作者: oo上海 | 来源:发表于2016-08-02 09:09 被阅读6次

    100. Same Tree

    题目:

    https://leetcode.com/problems/same-tree/

    难度:

    Easy

    递归

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

    相关文章

      网友评论

        本文标题:100. Same Tree

        本文链接:https://www.haomeiwen.com/subject/apsfsttx.html