Skip to content

Commit 5242d93

Browse files
authored
Merge pull request Sunchit#1043 from git5v/patch-107
Create 1768.MergeStringsAlternately.cpp
2 parents d6ebfd7 + 763e6bc commit 5242d93

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
string mergeAlternately(string word1, string word2) {
4+
5+
int n = word1.length(), m = word2.length();
6+
int i = 0, j = 0;
7+
string ans;
8+
9+
while(i<n and j<m)
10+
{
11+
ans+=word1[i];
12+
ans+=word2[j];
13+
i++;j++;
14+
}
15+
while(i<n) { ans+=word1[i]; i++;}
16+
while(j<m) { ans+=word2[j]; j++;}
17+
18+
return ans;
19+
}
20+
};

0 commit comments

Comments
 (0)