Python | Easy
see the Successfully Accepted Submission\n\n# Code\n\nclass Solution:\n    def minRemoveToMakeValid(self, s: str) -> str:\n        stack = []\n        to_remove
[see the Successfully Accepted Submission](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/submissions/1224541327/?envType=daily-question&envId=2024-04-06)\n\n# Code\n```\nclass Solution:\n    def minRemoveToMakeValid(self, s: str) -> str:\n        stack = []\n        to_remove = set()\n        \n        for i, char in enumerate(s):\n            if char == \'(\':\n                stack.append(i)\n            elif char == \')\':\n                if stack:\n                    stack.pop()\n                else:\n                    to_remove.add(i)\n        \n        # Add remaining unmatched opening parentheses to to_remove\n        to_remove.update(stack)\n        \n        # Construct the resulting string excluding characters to be removed\n        result = \'\'\n        for i, char in enumerate(s):\n            if i not in to_remove:\n                result += char\n        \n        return result\n\n```\n\n![image](https://assets.leetcode.com/users/images/b1e4af48-4da1-486c-bc97-b11ae02febd0_1696186577.992237.jpeg)
['Python3']