From 09ce49eb8b4e0a321779b8d2d02a847896ffba46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=8C=EC=B1=A0?= Date: Fri, 18 Dec 2020 05:11:55 +0900 Subject: [PATCH 1/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2b5ce843..538778af 100644 --- a/README.md +++ b/README.md @@ -203,6 +203,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu | 394 | [Decode String](https://leetcode.com/problems/decode-string/) | [C++](./C++/decode-string.cpp) | _O(n)_ | _O(1)_ | Medium | Stack | | | 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 | | | 32 | [Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/) | [Python](.Python/longest-valid-parentheses.py) | _O(n)_ | _O(n)_ | Hard | Stack | | +| 1249 | [Minimum Remove to Make Valid Parentheses](https://leetcode.com/problems/minimum-remove-to-make-valid-parentheses/) | [C++](./C++/minimum-remove-to-make-valid-parentheses.cpp) | _O(n)_ | _O(n)_ | Medium | Stack | |
⬆️ Back to Top From 1e15cfc8d2f2f1b8f7474064494bef331d5289be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=8C=EC=B1=A0?= Date: Fri, 18 Dec 2020 05:12:05 +0900 Subject: [PATCH 2/3] Create minimum-remove-to-make-valid-parentheses.cpp --- ...nimum-remove-to-make-valid-parentheses.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 C++/minimum-remove-to-make-valid-parentheses.cpp diff --git a/C++/minimum-remove-to-make-valid-parentheses.cpp b/C++/minimum-remove-to-make-valid-parentheses.cpp new file mode 100644 index 00000000..370a3345 --- /dev/null +++ b/C++/minimum-remove-to-make-valid-parentheses.cpp @@ -0,0 +1,35 @@ +class Solution { +public: + string minRemoveToMakeValid(string s) { + stack stack_for_index; //stack to save index of '(' + string result_string = ""; + + // count wrong parentheses with stack & make string + for (int i = 0; i < s.size(); i++) + { + if (s[i] == '(') { + stack_for_index.push(result_string.size()); + result_string.push_back(s[i]); + } + else if (s[i] == ')') { + if (!stack_for_index.empty()) { + stack_for_index.pop(); + result_string.push_back(s[i]); + } + } + else { + result_string.push_back(s[i]); + } + } + // now "stack_for_characters.size()" is the number of wrong "left" parentheses + + // remove wrong left parentheses + while (!stack_for_index.empty()) + { + result_string.erase(stack_for_index.top(), 1); + stack_for_index.pop(); + } + + return result_string; + } +}; \ No newline at end of file From e869afc7d5fcf7d419afc9c510805b00e4548a11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=96=8C=EC=B1=A0?= Date: Fri, 18 Dec 2020 05:27:39 +0900 Subject: [PATCH 3/3] edit wrong filename --- C++/{Network-delay-time.cpp.txt => Network-delay-time.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename C++/{Network-delay-time.cpp.txt => Network-delay-time.cpp} (100%) diff --git a/C++/Network-delay-time.cpp.txt b/C++/Network-delay-time.cpp similarity index 100% rename from C++/Network-delay-time.cpp.txt rename to C++/Network-delay-time.cpp