-
Notifications
You must be signed in to change notification settings - Fork 7
/
Main.java
31 lines (28 loc) · 901 Bytes
/
Main.java
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
package com.company;
public class Main {
public static void main(String[] args) {
// write your code here
}
public int numTeams(int[] rating) {
int[] smaller = new int[rating.length];
int[] bigger = new int[rating.length];
int res = 0;
for (int i = 0; i < rating.length; i++) {
for (int j = i + 1; j < rating.length; j++) {
if (rating[i] > rating[j])
smaller[i]++;
else if (rating[i] < rating[j])
bigger[i]++;
}
}
for (int i = 0; i < rating.length; i++) {
for (int j = i + 1; j < rating.length; j++) {
if (rating[i] > rating[j])
res += smaller[j];
else if (rating[i] < rating[j])
res += bigger[j];
}
}
return res;
}
}