-
Notifications
You must be signed in to change notification settings - Fork 3
/
1395.cpp
31 lines (31 loc) · 905 Bytes
/
1395.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class Solution {
public:
int numTeams(vector<int>& rating) {
int n = rating.size();
int res = 0;
for (int i = 0; i < n; i++) {
int leftLower = 0;
int leftHigher = 0;
int rightLower = 0;
int rightHigher = 0;
for (int j = 0; j < i; j++) {
if (rating[j] < rating[i]) {
leftLower++;
}
else if (rating[j] > rating[i]) {
leftHigher++;
}
}
for (int j = i + 1; j < n; j++) {
if (rating[j] < rating[i]) {
rightLower++;
}
else if (rating[j] > rating[i]) {
rightHigher++;
}
}
res += leftLower * rightHigher + leftHigher * rightLower;
}
return res;
}
};