File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed
22-Merge-Strings-Alternately Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change
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
+ };
Original file line number Diff line number Diff line change
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
+ };
Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ Solutions in various programming languages are provided. Enjoy it.
26
26
18 . 2023/02/09 [ #605 Can Place Flowers] ( https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/18-Can-Place-Flowers ) : Greedy
27
27
19 . 2023/02/10 [ #763 Partition Labels] ( https://github.com/LeetcodeRush/Leetcode/tree/main/Problems/19-Partition-Labels ) : Greedy
28
28
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
+
29
32
30
33
## Weekly Contest
31
34
You can’t perform that action at this time.
0 commit comments