Answers for "Minimum Remove to Make Valid Parentheses"

1

Minimum Remove to Make Valid Parentheses

var minRemoveToMakeValid = function(str) {
    str = str.split("");
	let stack = [];
    for(let i = 0; i<str.length; i++){
        if(str[i]==="(")
            stack.push(i);
        else if(str[i]===")"){
            if(stack.length) stack.pop();
            else str[i]="";
        }
    }
    
    for(let i of stack) str[i] = "";
    
    return str.join("");
	
}
Posted by: Guest on April-27-2021

Code answers related to "Minimum Remove to Make Valid Parentheses"

Code answers related to "Javascript"

Browse Popular Code Answers by Language