Python esay to understand


  • 2
    R
    class Solution(object):
    def isSymmetric(self, root):
        """
        :type root: TreeNode
        :rtype: bool
        """
        if root is None:
            return True
        return self.isS(root.left, root.right)
    
    def isS(self, left, right):
        if left is None and right is None:
            return True
        elif left is None or right is None:
            return False
            
        if left.val != right.val:
            return False
        return self.isS(left.left, right.right) and self.isS(left.right, right.left)

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.