-
Notifications
You must be signed in to change notification settings - Fork 1
/
1395.cpp
34 lines (30 loc) · 915 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
32
33
34
class Solution {
public:
int numTeams(vector<int>& rating) {
if(rating.empty()){
return 0;
}
int ans = 0;
for(int j=1; j<rating.size()-1; j++){
int i_smaller=0, i_larger=0, k_smaller=0, k_larger=0;
for(int i=0; i<j; i++) {
if(rating[i] < rating[j]){
i_smaller++;
}
else if(rating[i] > rating[j]){
i_larger++;
}
}
for(int k=j+1; k<rating.size(); k++) {
if(rating[j] < rating[k]){
k_larger++;
}
else if(rating[j] > rating[k]){
k_smaller++;
}
}
ans += i_smaller * k_larger + i_larger * k_smaller;
}
return ans;
}
};