-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
37 lines (37 loc) 路 729 Bytes
/
Copy pathSolution.java
File metadata and controls
37 lines (37 loc) 路 729 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
class Solution {
// DP
public int numTeams(int[] rating) {
int counter = 0;
int left = 0;
int right = 0;
for (int i = 0; i < rating.length; i++) {
left = 0; right = 0;
for (int l = 0; l < i; l++) {
if (rating[l] < rating[i]) {
left++;
}
}
for (int r = rating.length - 1; r > i; r--) {
if (rating[r] > rating[i]) {
right++;
}
}
counter += left * right;
}
for (int i = 0; i < rating.length; i++) {
left = 0; right = 0;
for (int l = 0; l < i; l++) {
if (rating[l] > rating[i]) {
left++;
}
}
for (int r = rating.length - 1; r > i; r--) {
if (rating[r] < rating[i]) {
right++;
}
}
counter += left * right;
}
return counter;
}
}