Skip to content

Commit d911e26

Browse files
committed
Time: 0 ms (100%), Space: 7.9 MB (32.94%) - LeetHub
1 parent 547964a commit d911e26

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Solution {
2+
public:
3+
int minAddToMakeValid(string s) {
4+
stack<char> stk;
5+
int ans = 0;
6+
for (auto& i : s) {
7+
if (i == ')') {
8+
if (!stk.empty()) {
9+
stk.pop();
10+
} else {
11+
ans++;
12+
}
13+
} else {
14+
stk.push(i);
15+
}
16+
}
17+
return ans + stk.size();
18+
}
19+
};

0 commit comments

Comments
 (0)