leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0921.cpp (374B)


0 class Solution {
1 public:
2 int minAddToMakeValid(const string &s) {
3 int res = 0, cnt = 0;
4 for (char c : s) {
5 if (c == '(')
6 cnt++;
7 else if (c == ')') {
8 if (cnt > 0)
9 cnt--;
10 else
11 res++;
12 }
13 }
14 return res + cnt;
15 }
16 };