Skip to content

Commit f761ca0

Browse files
authored
Create 1396-count-number-of-teams.js
1 parent 1c1a5eb commit f761ca0

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

1396-count-number-of-teams.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number[]} rating
3+
* @return {number}
4+
*/
5+
const numTeams = function(rating) {
6+
let res = 0
7+
for(let i = 1, n = rating.length; i < n - 1; i++) {
8+
const less = Array(2).fill(0), greater = Array(2).fill(0)
9+
for(let j = 0; j < n; j++) {
10+
if(rating[i] > rating[j]) {
11+
less[j < i ? 0 : 1]++
12+
}
13+
if(rating[i] < rating[j]) {
14+
greater[j > i ? 0 : 1]++
15+
}
16+
}
17+
res += less[0] * greater[0] + less[1] * greater[1]
18+
}
19+
return res
20+
};

0 commit comments

Comments
 (0)