코딩테스트
코딩테스트 연습 > 스택/큐 > 프린터
안양사람
2020. 8. 13. 16:36
728x90
SMALL
function solution(priorities, location) {
const obj=priorities.map((value,index)=>({index:index,value:value}));
let num=1;
while(true){
const max=Math.max.apply(Math, obj.map(i => { return i.value; }));
if(obj[0].value>=max){
if(obj[0].index===location){
return num;
}
obj.shift();
num++;
}else{
obj.push(obj[0]);
obj.shift();
}
}
}
이것도 생각해보면 간단한데 시간이 많이걸렸다.
그냥 map으로 index를 넣은 객체배열을 만들고 최대값을 가져오는 저 식만 알면 끝난다.
728x90
LIST