Skip to content

Commit af524cd

Browse files
authored
Create 2037. Minimum Number of Moves to Seat Everyone (#502)
2 parents c4feace + d23e4f2 commit af524cd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
int minMovesToSeat(vector<int>& seats, vector<int>& students) {
4+
const int n=seats.size();
5+
sort(seats.begin(), seats.end());
6+
sort(students.begin(), students.end());
7+
int moves=0;
8+
for (int i=0; i<n; i++)
9+
moves+=abs(students[i]-seats[i]);
10+
return moves;
11+
}
12+
};
13+
14+
15+
16+
17+
18+
auto init = []() {
19+
ios::sync_with_stdio(false);
20+
cin.tie(nullptr);
21+
cout.tie(nullptr);
22+
return 'c';
23+
}();

0 commit comments

Comments
 (0)