Skip to content

Commit c5943dc

Browse files
authored
Add Solution of "minimum-add-to-make-parentheses-valid" & Update README.md (#146)
1 parent 9125018 commit c5943dc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/
2+
3+
class Solution {
4+
public:
5+
int minAddToMakeValid(string S) {
6+
int result = 0;
7+
8+
stack<char> s; //stack to save '('
9+
10+
for (int i = 0; i < S.size(); i++)
11+
{
12+
if (S[i] == '(') {
13+
s.push('(');
14+
}
15+
else {
16+
if (s.empty()) {
17+
result++;
18+
}
19+
else {
20+
s.pop();
21+
}
22+
}
23+
}
24+
25+
result = result + s.size();
26+
27+
return result;
28+
}
29+
};

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
201201
| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [Python](./Python/binary-tree-inorder-traversal.py) | _O(n)_ | _O(n)_ | Medium | Recursion, Binary Tree |
202202
| 735 | [Asteroid Collision](https://leetcode.com/problems/asteroid-collision/) | [C++](./C++/asteroid-collision.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | |
203203
| 394 | [Decode String](https://leetcode.com/problems/decode-string/) | [C++](./C++/decode-string.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | |
204+
| 921 | [Minimum Add to Make Parentheses Valid](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) | [C++](./C++/minimum-add-to-make-parentheses-valid.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | |
204205

205206
<br/>
206207
<div align="right">
@@ -472,6 +473,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
472473
| [Anushka Verma](https://github.com/verma-anushka) <br> <img src="https://avatars0.githubusercontent.com/u/46157435?s=400&u=aa3db9cf25b4a9644a16607d0c8bd6c98763a62d&v=4" width="100" height="100"> | India | C++ | [Portfolio](https://verma-anushka.github.io/anushkaverma/) <br> [LeetCode](https://leetcode.com/anushka_verma/) |
473474
| [James H](https://github.com/HoangJames) <br> <img src="https://avatars2.githubusercontent.com/u/15057250?s=460&v=4" width="100" height="100"> | United Kingdom | C++ | [Github](https://github.com/HoangJames) |
474475
| [Franchis N. Saikia](https://github.com/Francode007) <br> <img src="https://avatars0.githubusercontent.com/u/63102937?s=400&v=4" width="100" height="100"> | India | C++ | [Github](https://github.com/Francode007) |
476+
| [Yarncha](https://github.com/yarncha) <br> <img src="https://avatars0.githubusercontent.com/u/33623182?s=400&v=4" width="100" height="100"> | South Korea | C++ | [LeetCode](https://leetcode.com/yamcha/) |
475477
<br/>
476478
<div align="right">
477479
<b><a href="#algorithms">⬆️ Back to Top</a></b>

0 commit comments

Comments
 (0)