1768_交替合并字符串
小于 1 分钟
1768_交替合并字符串简单
class Solution {
public String mergeAlternately(String word1, String word2) {
StringBuilder res = new StringBuilder();
int len = Math.min(word1.length(), word2.length());
for (int i = 0; i < len; i++) {
res.append(word1.charAt(i));
res.append(word2.charAt(i));
}
return res.append(len == word1.length() ? word2.substring(len):word1.substring(len)).toString();
}
}
Powered by Waline v2.15.5