Skip to content

Commit a0154e0

Browse files
authored
Merge pull request #3187 from Dalton-V/main
Added 1768-merge-strings-alternately.cs
2 parents 8e141c9 + 96b9163 commit a0154e0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: csharp/1768-merge-strings-alternately.cs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Solution
2+
{
3+
public string MergeAlternately(string word1, string word2)
4+
{
5+
var result = string.Empty;
6+
var firstPointer = 0;
7+
var secondPointer = 0;
8+
while (firstPointer < word1.Length || secondPointer < word2.Length)
9+
{
10+
if (firstPointer < word1.Length)
11+
result += word1[firstPointer++];
12+
13+
if (secondPointer < word2.Length)
14+
result += word2[secondPointer++];
15+
}
16+
return result;
17+
}
18+
}

0 commit comments

Comments
 (0)