우선, 의식의 흐름대로 풀었다.
한 코어의 작업이 끝나면(0이 되면) 다음 작업을 실행시킨다.(n--)
이렇게 푸는건 이젠 금방금방 구현할 수 있었다. (Priority Queue로도 가능할 듯하다).
근데,,, 효율성에서 막혔다..
효율성 통과하는 방법은 모르겠다.. 더 고민해보자..
import java.util.*;
class Solution {
static class Core {
int index;
int time;
public Core(int index, int time) {
this.index = index;
this.time = time;
}
}
public static int solution(int n, int[] cores) {
int answer = 0;
ArrayList<Core> list = new ArrayList<>();
for (int i = 0; i < cores.length; i++) {
list.add(new Core(i+1,cores[i]));
n -= 1;
}
boolean over = true;
while( over ) {
for( Core core : list ) {
core.time --;
if( core.time == 0 ) {
n--;
answer = core.index;
list.set(core.index-1, new Core(core.index, cores[core.index-1]));
if( n == 0 ) {
over = false;
break;
}
}
}
}
return answer;
}
}