commit d6f37938238c723c3d5c22c960f869677a17d3b7
parent 5ccf2f8a3aa3207556aeaee792e774498fe98d1f
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date: Wed, 1 May 2024 12:02:25 +0200
Daily Problem
Diffstat:
2 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/Problems/2000.cpp b/Problems/2000.cpp
@@ -0,0 +1,19 @@
+class Solution {
+ public:
+ string reversePrefix(string word, char ch) const {
+ const int n = size(word);
+ int i;
+
+ for (i = 0; i < n; i++) {
+ if (word[i] == ch) break;
+ }
+
+ if (i == n) return word;
+
+ int j = 0;
+ while (j < i)
+ swap(word[i--], word[j++]);
+
+ return word;
+ }
+};
diff --git a/README.md b/README.md
@@ -994,6 +994,7 @@ for solving problems.
| 1980 | Medium | [Find Unique Binary String](Problems/1980.cpp) |
| 1991 | Easy | [Find the Middle Index in Array](Problems/1991.cpp) |
| 1992 | Medium | [Find All Groups of Farmland](Problems/1992.cpp) |
+| 2000 | Easy | [Reverse Prefix of Word](Problems/2000.cpp) |
| 2002 | Medium | [Maximum Product of the Length of Two Palindromic Subsequences](Problems/2002.cpp) |
| 2009 | Hard | [Minimum Number of Operations to Make Array Continuous](Problems/2009.cpp) |
| 2023 | Medium | [Number of Pairs of Strings With Concatenation Equal to Target](Problems/2023.cpp) |