
나의 풀이
class Solution {
public String solution(int[] food) {
String answer = "";
StringBuilder sb = new StringBuilder();
for(int i = 1; i < food.length ; i++){
for(int j = 0; j < food[i] / 2 ; j++){
sb.append(i);
}
}
answer = sb.toString() + "0" + sb.reverse();
return answer;
}
}
다른 사람의 풀이
class Solution {
public String solution(int[] food) {
String answer = "0";
for (int i = food.length - 1; i > 0; i--) {
for (int j = 0; j < food[i] / 2; j++) {
answer = i + answer + i;
}
}
return answer;
}
}
'알고리즘' 카테고리의 다른 글
| [프로그래머스] 모의고사(Java) * (0) | 2024.12.11 |
|---|---|
| [프로그래머스] 콜라 문제(Java) * (0) | 2024.12.06 |
| [프로그래머스] 가장 가까운 같은 글자(Java) * (0) | 2024.12.04 |
| [프로그래머스] 두 개 뽑아서 더하기(Java) * (0) | 2024.12.03 |
| [프로그래머스] 숫자 문자열과 영단어(Java) * (0) | 2024.12.02 |