C# beats 98.66% using Stack
Runtime: 88 ms, faster than 98.66% of C# online submissions for Minimum Remove to Make Valid Parentheses.\nMemory Usage: 34.8 MB, less than 100.00% of C# online
Runtime: 88 ms, faster than 98.66% of C# online submissions for Minimum Remove to Make Valid Parentheses.\nMemory Usage: 34.8 MB, less than 100.00% of C# online submissions for Minimum Remove to Make Valid Parentheses.\n```\npublic class Solution\n{\n    public string MinRemoveToMakeValid(string s)\n    {\n        var res = new StringBuilder();\n        var openPos = new Stack<int>();\n        int i = 0;\n        foreach (var c in s)\n            switch (c)\n            {\n                case \'(\':\n                    res.Append(c);\n                    openPos.Push(i++);\n                    break;\n                case \')\':\n                    if (openPos.Any())\n                    {\n                        res.Append(c);\n                        openPos.Pop();\n                        i++;\n                    }\n                    break;\n                default:\n                    res.Append(c);\n                    i++;\n                    break;\n            }\n\n        while (openPos.Any())\n        {\n            var pos = openPos.Pop();\n            res.Remove(pos, 1);\n        }\n\n        return res.ToString();\n    }\n}\n```
['C#']