commit 7e6a963ee2ee8bb5d66a64201574fa5e41b108e4
parent 71190176774e5c600d9869afc2c7ef13099946c5
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Fri, 17 Feb 2023 15:48:15 +0100
Data Structure II: Day 14
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/1249.cpp b/Problems/1249.cpp
@@ -0,0 +1,19 @@
+class Solution {
+public:
+ string minRemoveToMakeValid(string s) {
+ stack<int> st;
+ for (auto i = 0; i < s.size(); i++) {
+ if (s[i] == '(')
+ st.push(i);
+ else if (s[i] == ')') {
+ if (!st.empty())
+ st.pop();
+ else
+ s[i] = '*';
+ }
+ }
+ while (!st.empty()) s[st.top()] = '*', st.pop();
+ s.erase(remove(s.begin(), s.end(), '*'), s.end());
+ return s;
+ }
+};
diff --git a/README.md b/README.md
@@ -354,6 +354,7 @@ for solving problems.
| 1162 | Medium | [As Far from Land as Possible](Problems/1162.cpp) |
| 1202 | Medium | [Smallest String With Swaps](Problems/1202.cpp) |
| 1209 | Medium | [Remove All Adjacent Duplicates in String II](Problems/1209.cpp) |
+| 1249 | Medium | [Minimum Remove to Make Valid Parentheses](Problems/1249.cpp) |
| 1290 | Easy | [Convert Binary Number in a Linked List to Integer](Problems/1290.cpp) |
| 1302 | Medium | [Deepest Leaves Sum](Problems/1302.cpp) |
| 1305 | Medium | [All Elements in Two Binary Search Trees](Problems/1305.cpp) |