leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

2037.cpp (478B)


      1 class Solution {
      2   public:
      3     int minMovesToSeat(const vector<int> &seats, const vector<int> &students) const {
      4         static int count[101];
      5 
      6         memset(count, 0x00, sizeof(count));
      7         for (const int n : seats)
      8             count[n]++;
      9         for (const int n : students)
     10             count[n]--;
     11 
     12         int res = 0, unmatched = 0;
     13         for (int n : count) {
     14             res += abs(unmatched);
     15             unmatched += n;
     16         }
     17 
     18         return res;
     19     }
     20 };