[Algorithm] 15 week(4.18 ~ 4.24) 3/3

Dev_min·2022년 4월 22일
0

algorithm

목록 보기
49/157

2037. Minimum Number of Moves to Seat Everyone

var minMovesToSeat = function(seats, students) {
    const sortedSeats = [...seats].sort((a, b) => a - b);
    const sortedStudents = [...students].sort((a, b) => a - b);
    
    let result = 0;
    
    sortedStudents.forEach((student, index) => {
        result += Math.abs(student - sortedSeats[index]);
    });
    
    return result;
};
profile
TIL record

0개의 댓글