Skip to content

Commit 86d97c9

Browse files
committed
added Description
1 parent 0e960d6 commit 86d97c9

File tree

1 file changed

+15
-0
lines changed
  • Minimum Add to Make Parentheses Valid

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* @param {string} S
3+
* @return {number}
4+
*/
5+
var minAddToMakeValid = function(S) {
6+
let open = 0, close = 0;
7+
8+
for(let c of S) {
9+
if(c === '(') open++;
10+
else if(!open) close++;
11+
else open--;
12+
}
13+
return open + close;
14+
};
15+

0 commit comments

Comments
 (0)