思路:
跟归并排序思路类似。
无需多言。
class Solution {
public:
string mergeAlternately(string word1, string word2) {
int i = 0 , j = 0 , k = 0 ;
int len1 = word1.size();
int len2 = word2.size();
string word3 ;
while( i < len1 && j<len2){
word3.insert(k++,1,word1[i++]);
word3.insert(k++,1,word2[j++]);
}
while( i < len1){
word3.insert(k++,1,word1[i++]);
}
while( j < len2){
word3.insert(k++,1,word2[j++]);
}
return word3;
}
};