Python DFS recursive


  • 0
    M
    def invertTree(self, root):
            """
            :type root: TreeNode
            :rtype: TreeNode
            """
            if root:
                self.invertTree(root.left)
                self.invertTree(root.right)
                temp = root.right
                root.right = root.left
                root.left = temp
            
            return root
    

Log in to reply
 

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