Skip to content

Commit c000828

Browse files
committed
https://leetcode.cn/problems/minimum-number-of-moves-to-seat-everyone/
1 parent 8866250 commit c000828

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ Step 2. Add the dependency
4949

5050
<summary>展开查看</summary>
5151

52+
https://leetcode.cn/problems/minimum-number-of-moves-to-seat-everyone/
53+
5254
https://leetcode.cn/problems/time-needed-to-inform-all-employees
5355

5456
https://leetcode.cn/problems/rotting-oranges
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default function minMovesToSeat(
2+
seats: number[],
3+
students: number[],
4+
): number {
5+
seats.sort((a, b) => a - b);
6+
students.sort((a, b) => a - b);
7+
8+
return seats.reduce((p, c, i) => p + Math.abs(c - students[i]), 0);
9+
}

0 commit comments

Comments
 (0)