leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
1395.cpp (486B)
0 class Solution { 1 public: 2 int numTeams(const vector<int> &rating) { 3 int res = 0; 4 for (int i = 1; i < rating.size() - 1; i++) { 5 int less[2] = {}, greater[2] = {}; 6 for (auto j = 0; j < rating.size(); j++) { 7 if (rating[i] < rating[j]) less[j > i]++; 8 if (rating[i] > rating[j]) greater[j > i]++; 9 } 10 res += less[0] * greater[1] + greater[0] * less[1]; 11 } 12 return res; 13 } 14 };