Minimum Add to Make Parentheses Valid LeetCode solution in JavaScript
1var minAddToMakeValid = function (s) {2let stack = [];3let count = 0;4for (let i = 0; i < s.length; i++) {5let ch = s[i];6if (ch === "(") {7stack.push(ch);8} else {9let top = stack.pop();10if (top != "(") count++;11}12}1314count += stack.length;1516return count;17};