-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.java
More file actions
40 lines (39 loc) · 1017 Bytes
/
Copy pathSolution.java
File metadata and controls
40 lines (39 loc) · 1017 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
class Solution
{
public int numTeams(int[] rating)
{
final int n = rating.length;
int teams = 0;
final int[] increasing = new int[n];
final int[] decreasing = new int[n];
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (rating[i] < rating[j])
{
decreasing[i]++;
}
if (rating[i] > rating[j])
{
increasing[i]++;
}
}
}
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (rating[i] < rating[j] && decreasing[j] > 0)
{
teams += decreasing[j];
}
if (rating[i] > rating[j] && increasing[j] > 0)
{
teams += increasing[j];
}
}
}
return teams;
}
}