public String mergeAlternately(String word1, String word2) {
int m = word1.length(), n = word2.length();
int i = 0, j = 0;
StringBuilder ans = new StringBuilder();
while (i < m || j < n) {
if (i < m) {
ans.append(word1.charAt(i));
++i;
}
if (j < n) {
ans.append(word2.charAt(j));
++j;
}
}
return ans.toString();
}
2022.10.23-----leetcode.1768
最新推荐文章于 2024-08-30 11:28:00 发布