Swift Easy Solution


  • 0
    C
    func invertTree(root: TreeNode?) -> TreeNode? {
        if root == nil{
            return nil
        }
        
        invertTree(root?.left)
        invertTree(root?.right)
        
        let temp = root?.left
        root?.left = root?.right
        root?.right = temp
        
        return root
    }

Log in to reply
 

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