-Code
class Solution {
public String solution(int[] food) {
StringBuilder answer = new StringBuilder();
int water = food[0] + 1;
for (int i = 1; i < food.length; i++) {
answer.append(String.valueOf(i).repeat(food[i] / water));
}
StringBuilder reverse = new StringBuilder(answer).reverse();
answer.append(0);
answer.append(reverse);
return answer.toString();
}
}
'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
[프로그래머스/Java] 콜라 문제 (0) | 2025.02.26 |
---|---|
[프로그래머스/Java] 문자열 내 마음대로 정렬하기 (0) | 2025.02.26 |
[프로그래머스/Java] 숫자 문자열과 영단어 (0) | 2025.02.25 |
[프로그래머스/Java] 두 개 뽑아서 더하기 (0) | 2025.02.25 |
[프로그래머스/Java] 가장 가까운 같은 글자 (0) | 2025.02.25 |