[Algorithm] 39 week(10.24 ~ 10.30) 3/3

Dev_min·2022년 10월 26일
0

algorithm

목록 보기
128/157

406. Queue Reconstruction by Height

var reconstructQueue = function(people) {
    const sorted = [...people].sort(sortPeople);
    const result = [];

    for(let i = 0; i < sorted.length; i++){
        result.splice(sorted[i][1], 0, sorted[i]);
    }

    return result;
};

const sortPeople = (a, b) => {
    if(a[0] !== b[0]){
        return b[0] - a[0];
    } else {
        return a[1] - b[1];
    }
}
profile
TIL record

0개의 댓글