We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e5d3654 commit 695011cCopy full SHA for 695011c
Problems/22-Merge-Strings-Alternately/1768.ts
@@ -0,0 +1,18 @@
1
+function mergeAlternately(word1: string, word2: string): string {
2
+ let ptr1: number = 0;
3
+ let ptr2: number = 0;
4
+ const len1 = word1.length;
5
+ const len2 = word2.length;
6
+ let res: string[] = [];
7
+ while (ptr1 < len1 || ptr2 < len2) {
8
+ if (ptr1 < len1 && ptr2 < len2) {
9
+ res.push(word1[ptr1++]);
10
+ res.push(word2[ptr2++]);
11
+ } else if (ptr1 > len1 || ptr2 < len2) {
12
13
+ } else if (ptr1 < len1 || ptr2 > len2) {
14
15
+ }
16
17
+ return res.join("");
18
+}
0 commit comments