
-Code
class Solution {
public String mergeAlternately(String word1, String word2) {
StringBuilder sb = new StringBuilder();
int wordLength1 = word1.length();
int wordLength2 = word2.length();
int idx1 = 0;
int idx2 = 0;
while (idx1 + idx2 < wordLength1 + wordLength2) {
if (idx1 < wordLength1) {
sb.append(word1.charAt(idx1));
idx1++;
}
if (idx2 < wordLength2) {
sb.append(word2.charAt(idx2));
idx2++;
}
}
return sb.toString();
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [LeetCode/Java] Kids With the Greatest Number of Candies (0) | 2025.12.19 |
|---|---|
| [LeetCode/Java] Greatest Common Divisor of Strings (0) | 2025.12.19 |
| [백준/Java] 2446번 별 찍기 - 9 (0) | 2025.12.19 |
| [백준/Java] 11719번 그대로 출력하기 2 (0) | 2025.12.19 |
| [백준/Java] 3009번 네 번째 점 (0) | 2025.12.19 |