Count Number of Teams LeetCode solution in C++

1
class Solution {
2
public:
3
int numTeams(vector<int> &rating) {
4
int i, j, n = rating.size(), ans = 0;
5
vector<int> grt(n, 0), les(n, 0);
6
for (i = 0; i < n; i++) {
7
for (j = i + 1; j < n; j++) {
8
if (rating[j] > rating[i])
9
grt[i] += 1;
10
else
11
les[i] += 1;
12
}
13
}
14

15
for (i = 0; i < n; i++) {
16
for (j = i + 1; j < n; j++) {
17
if (rating[j] > rating[i])
18
ans += grt[j];
19
else
20
ans += les[j];
21
}
22
}
23
return ans;
24
}
25
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0