1var minRemoveToMakeValid = function(str) {
2 str = str.split("");
3 let stack = [];
4 for(let i = 0; i<str.length; i++){
5 if(str[i]==="(")
6 stack.push(i);
7 else if(str[i]===")"){
8 if(stack.length) stack.pop();
9 else str[i]="";
10 }
11 }
12
13 for(let i of stack) str[i] = "";
14
15 return str.join("");
16
17}
18