leetcode

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

1817.cpp (702B)


      1 class Solution {
      2   public:
      3     vector<int> findingUsersActiveMinutes(vector<vector<int>> &logs, int k) {
      4         sort(logs.begin(), logs.end());
      5 
      6         vector<int> res(k, 0);
      7         int crnt = logs.front()[0], val = logs.front()[1], count = 1;
      8         for (const auto &log : logs) {
      9             if (log[0] == crnt) {
     10                 if (log[1] == val) continue;
     11                 val = log[1];
     12                 count++;
     13             } else {
     14                 if (count >= 1 && count <= k) res[count - 1]++;
     15                 crnt = log[0];
     16                 val = log[1];
     17                 count = 1;
     18             }
     19         }
     20         if (count >= 1 && count <= k) res[count - 1]++;
     21         return res;
     22     }
     23 };