7 line Python recursive solution, easy to understand


  • 0
    Z

    Pass time: 35-45ms

        def isSymmetric(self, root):
            if not root: return True
            
            def dfs(left, right):
                if not left or not right: 
                    return left == right
                
                return dfs(left.left, right.right) and dfs(left.right, right.left) and left.val == right.val
            
            return dfs(root.left, root.right)
    

Log in to reply
 

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