-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLC_1395.cpp
More file actions
26 lines (26 loc) · 753 Bytes
/
LC_1395.cpp
File metadata and controls
26 lines (26 loc) · 753 Bytes
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
class Solution {
public:
int numTeams(vector<int>& rating) {
int i,j,k,len=rating.size(),con=0;
for(i=0;i<len;i++)
{
int leftlower=0,righthigher=0,lefthigher=0,rightlower=0;
for(j=i-1;j>=0;j--)
{
if(rating[j]<rating[i])
leftlower++;
else if(rating[j]>rating[i])
lefthigher++;
}
for(j=i+1;j<len;j++)
{
if(rating[j]>rating[i])
righthigher++;
else if(rating[j]<rating[i])
rightlower++;
}
con=con + (leftlower*righthigher) + (lefthigher*rightlower);
}
return con;
}
};