Skip to content

Commit 251b9c5

Browse files
committed
leetcode_1768
1 parent 37699ed commit 251b9c5

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

1768_Merge_Strings_Alternately.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
string mergeAlternately(string word1, string word2) {
4+
int mx= max(word1.length(), word2.length());
5+
int mn= min(word1.length(), word2.length());
6+
int i=0;
7+
string ret;
8+
while(i<mn){
9+
ret+=word1[i];
10+
ret+=word2[i++];
11+
}
12+
string* ptr = word1.length() > word2.length()? &word1 : &word2;
13+
while(i<mx){
14+
ret+= (*ptr)[i++];
15+
}
16+
return ret;
17+
}
18+
};

0 commit comments

Comments
 (0)