코드
function solution(priorities, location) {
let count = 1;
priorities = priorities.map((ele, index) => [index, ele]);
while (true) {
let max = priorities[0][1];
for (let i = 1; i < priorities.length; i++) {
if (max < priorities[i][1]) max = priorities[i][1];
}
if (priorities[0][1] >= max) {
if (priorities[0][0] === location) return count;
priorities.shift();
count++;
} else {
priorities.push(priorities.shift());
}
}
}
map을 이용해서 배열의 index를 저장해놓고 시작함
'코딩 테스트 > 프로그래머스 level2' 카테고리의 다른 글
k진수에서 소수 개수 구하기 (0) | 2022.09.12 |
---|---|
[1차] 뉴스 클러스터링 (0) | 2022.09.12 |
기능개발 (0) | 2022.09.12 |
n^2 배열 자르기 (0) | 2022.09.11 |
위장 (0) | 2022.09.11 |