1768. Merge Strings Alternately leetcode solution in c++
#include <string>
class Solution {
public:
std::string mergeAlternately(std::string word1, std::string word2) {
int i = 0, j = 0;
std::string result;
while (i < word1.length() && j < word2.length()) {
result += word1[i++];
result += word2[j++];
}
while (i < word1.length()) {
result += word1[i++];
}
while (j < word2.length()) {
result += word2[j++];
}
return result;
}
};