swift: stack
\nclass Solution {\n    \n    func minRemoveToMakeValid(_ s: String) -> String {\n        var arr = Array(s)\n        var stack = [Int]()\n        for (i, c) in
```\nclass Solution {\n    \n    func minRemoveToMakeValid(_ s: String) -> String {\n        var arr = Array(s)\n        var stack = [Int]()\n        for (i, c) in arr.enumerated() {\n            if c == "(" {\n                stack.append(i)\n            } else if c == ")" {\n                if !stack.isEmpty {\n                    stack.removeLast()\n                } else {\n                    arr[i] = "*"\n                }\n            }\n        }\n        while !stack.isEmpty {\n            let i = stack.removeLast()\n            arr[i] = "*"\n        }\n        \n        return String(arr).replacingOccurrences(of: "*", with: "")\n      \n    }\n}\n```
[]