Skip to content

Commit

Permalink
Solve: Minimum Add to Make Parentheses Valid
Browse files Browse the repository at this point in the history
  • Loading branch information
fkdl0048 authored Oct 9, 2024
1 parent 74cb042 commit e4b0cba
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions LeetCode/Minimum Add to Make Parentheses Valid.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution {
public:
int minAddToMakeValid(string s) {
int open = 0, close = 0;

for (int i = 0; i < s.size(); i++) {
if (s[i] == '(')
open++;
else {
close++;
if (open > 0) {
open--;
close--;
}
}
}

return open + close;
}
};

0 comments on commit e4b0cba

Please sign in to comment.