码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode——101. 对称二叉树

时间:2019-11-10 19:23:31      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:not   执行   bool   iss   etc   pytho   val   type   tree   

class Solution(object):
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        if not root:return True
        def Tree(p,q):
            if not p and not q:return True
            if p and q and p.val==q.val:
                return Tree(p.left,q.right) and Tree(p.right,q.left)
            return False
        return Tree(root.left,root.right)
执行用时 :24 ms, 在所有 python 提交中击败了76.38%的用户
内存消耗 :12 MB, 在所有 python 提交中击败了14.26%的用户
 
 
——2019.11.10

leetcode——101. 对称二叉树

标签:not   执行   bool   iss   etc   pytho   val   type   tree   

原文地址:https://www.cnblogs.com/taoyuxin/p/11831138.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!