Python solution with detailed explanation

  • 0


    Symmetric Tree

    • Simple recursive solution
    class Solution(object):
        def isSymmetric(self, root):
            if root == None:
                return True
            return self.helper(root.left, root.right)
        def helper(self, p, q):
            :type root: TreeNode
            :rtype: bool
            if p == None and q == None:
                return True
            elif p and q and p.val == q.val and self.helper(p.left, q.right) and self.helper(p.right, q.left):
                return True
                return False

Log in to reply

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