1768. Merge Strings Alternately

ss
Feb 21, 2021

--

復盤, 就左右放, 放到完, 看code應該就能理解了

class Solution {
public:
string mergeAlternately(string word1, string word2) {
int i = 0;
int j = 0;
string res = "";
while(i < word1.size() || j < word2.size()){
if(i < word1.size()){
res += word1[i];
i++;
}
if(j < word2.size()){
res += word2[j];
j++;
}
}
return res;
}
};

--

--

ss
ss

No responses yet