leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
2037.cpp (478B)
0 class Solution {
1 public:
2 int minMovesToSeat(const vector<int> &seats, const vector<int> &students) const {
3 static int count[101];
5 memset(count, 0x00, sizeof(count));
6 for (const int n : seats)
7 count[n]++;
8 for (const int n : students)
9 count[n]--;
11 int res = 0, unmatched = 0;
12 for (int n : count) {
13 res += abs(unmatched);
14 unmatched += n;
15 }
17 return res;
18 }
19 };