티스토리 뷰
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
'코딩테스트' 카테고리의 다른 글
코딩테스트 연습 > 2020 KAKAO BLIND RECRUITMENT > 문자열 압축 (0) | 2020.08.17 |
---|---|
코딩테스트 연습 > 정렬 > 가장 큰 수 (0) | 2020.08.13 |
코딩테스트 연습 > 스택/큐 > 다리를 지나는 트럭 (0) | 2020.08.12 |
코딩테스트 연습 > 스택/큐 > 기능개발 (0) | 2020.08.11 |
코딩테스트 연습 > 2019 KAKAO BLIND RECRUITMENT > 오픈채팅방 (0) | 2020.08.11 |
댓글
공지사항