-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
문제
핵심 아이디어
어려운 점, 실수
풀이
import java.util.*;
class Solution {
public String solution(int[] food) {
Queue<Integer> queue = new LinkedList<>();
for (int i = 1; i < food.length; i++) {
int num = i;
if (food[i] % 2 == 0) {
for (int j = 0; j < food[i] / 2; j++) {
queue.add(num);
}
} else {
for (int j = 0; j < (food[i] - 1) / 2; j++) {
queue.add(num);
}
}
}
StringBuilder sb = new StringBuilder();
Stack<Integer> stack = new Stack<>();
for (Integer i : queue) {
sb.append(i);
stack.add(i);
}
sb.append("0");
while(!stack.isEmpty()) {
sb.append(stack.pop());
}
return String.valueOf(sb);
}
}