Swift
```\n    func removeDuplicates(_ S: String) -> String {\n        var stack = Character\n        for char in S {\n            if let last = stack.last, last == c
```\n    func removeDuplicates(_ S: String) -> String {\n        var stack = [Character]()\n        for char in S {\n            if let last = stack.last, last == char {\n                stack.removeLast()\n            } else {\n                stack.append(char)\n            }\n        }\n        return String(stack)\n    }
[]