class Solution {
public String mergeAlternately(String word1, String word2) {
StringBuilder res = new StringBuilder();
int word1Index = 0, word2Index = 0;
while (word1Index < word1.length() && word2Index < word2.length()) {
res.append(word1.charAt(word1Index));
res.append(word2.charAt(word2Index));
++word1Index;
++word2Index;
}
if (word1Index < word1.length()) {
res.append(word1.substring(word1Index, word1.length()));
} else if (word2Index < word2.length()) {
res.append(word2.substring(word2Index, word2.length()));
}
return res.toString();
}
}