Skip to content

Commit ef64fdc

Browse files
committed
Add C++ 21 22 solutions
1 parent 4d37c5a commit ef64fdc

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

Problems/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int minFlips(string target) {
4+
int n = target.size();
5+
int ans = 0;
6+
for (int i = 0; i < n; i++)
7+
{
8+
if ((ans % 2 == 0 && target[i] != '0') || (ans % 2 == 1 && target[i] == '0')) ans++;
9+
}
10+
return ans;
11+
}
12+
};
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
string mergeAlternately(string word1, string word2) {
4+
int n = word1.length();
5+
int m = word2.length();
6+
string s = "";
7+
8+
int i = 0, j = 0;
9+
while (i < n and j < m)
10+
{
11+
s += word1[i++];
12+
s += word2[j++];
13+
}
14+
if (i == n)
15+
{
16+
while (j < m) s+= word2[j++];
17+
}
18+
if (j == m)
19+
{
20+
while (i < n) s+= word1[i++];
21+
}
22+
return s;
23+
}
24+
};

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Solutions in various programming languages are provided. Enjoy it.
2626
18. 2023/02/09 [#605 Can Place Flowers](https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/18-Can-Place-Flowers): Greedy
2727
19. 2023/02/10 [#763 Partition Labels](https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/19-Partition-Labels): Greedy
2828
20. 2023/02/11 [#2405 Optimal Partition of String](https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/20-Optimal-Partition-of-String): Greedy
29+
21. 2023/02/12 [#1529 Minimum Suffix Flips](): Greedy
30+
22. 2023/02/13 [#1768 Merge Strings Alternately](): String
31+
2932

3033
## Weekly Contest
3134

0 commit comments

Comments
 (0)