티스토리 뷰

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
댓글
공지사항