leetcode

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

1395.cpp (486B)


      1 class Solution {
      2   public:
      3     int numTeams(const vector<int> &rating) {
      4         int res = 0;
      5         for (int i = 1; i < rating.size() - 1; i++) {
      6             int less[2] = {}, greater[2] = {};
      7             for (auto j = 0; j < rating.size(); j++) {
      8                 if (rating[i] < rating[j]) less[j > i]++;
      9                 if (rating[i] > rating[j]) greater[j > i]++;
     10             }
     11             res += less[0] * greater[1] + greater[0] * less[1];
     12         }
     13         return res;
     14     }
     15 };