Minimum Remove to Make Valid Parentheses LeetCode solution in Python
1class Solution:2def minRemoveToMakeValid(self, s):3stack = []4split_str = list(s)5for i in range(len(s)):6if s[i] == "(":7# if current char is '(' then push it to stack8stack.append(i)9elif s[i] == ")":10# if current char is ')' then pop top of the stack11if len(stack) != 0:12stack.pop()13else:14# if our stack is empty then we can't pop so make current char as ''15split_str[i] = ""16for i in stack:17split_str[i] = ""18return "".join(split_str)