코딩테스트-알고리즘/프로그래머스
[프로그래머스/Lv.1] 푸드 파이트 대회
닉네임생각즁
2024. 4. 1. 23:51
https://school.programmers.co.kr/learn/courses/30/lessons/134240?language=java
class Solution {
public String solution(int[] food) {
String answer = "";
for (int i = 0; i < food.length; i++) {
food[i] = food[i] / 2;
}
for (int i = 1; i < food.length; i++) {
int index = 0;
while (index < food[i]) {
answer += i;
index++;
}
}
answer += "0";
for (int i = food.length-1; i > 0; i--) {
int index = 0;
while (index < food[i]) {
answer += i;
index++;
}
}
return answer;
}
}