Skip to content

Commit c9c02d7

Browse files
committed
feat(rank): ✨整理 5369
1 parent 9b3ad01 commit c9c02d7

File tree

2 files changed

+49
-7
lines changed

2 files changed

+49
-7
lines changed

Rank/182/solution2.js renamed to Rank/182/5369/solution1.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
/**
2+
* https://leetcode-cn.com/problems/count-number-of-teams/
3+
*
4+
* 5369. 统计作战单位数
5+
*
6+
* Medium
7+
*/
18
const numTeams = rating => {
29
let ans = 0;
310
const max = rating.length;
@@ -16,11 +23,4 @@ const numTeams = rating => {
1623
}
1724

1825
return ans;
19-
}
20-
21-
function getCount(count) {
22-
if (count < 3) {
23-
return 0;
24-
}
25-
return count * (count - 1) * (count - 2) / 6
2626
}

Rank/182/5369/solution2.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* https://leetcode-cn.com/problems/count-number-of-teams/
3+
*
4+
* 5369. 统计作战单位数
5+
*
6+
* Medium
7+
*
8+
* 64ms 100.00%
9+
* 34.2mb 100.00%
10+
*/
11+
const numTeams = rating => {
12+
let ans = 0;
13+
const max = rating.length;
14+
for (let i = 1; i < max; i++) {
15+
const middle = rating[i];
16+
let c1 = i - 1;
17+
let maxCount1 = 0;
18+
let minCount1 = 0;
19+
while (c1 >= 0) {
20+
if (rating[c1] < middle) {
21+
minCount1++;
22+
} else if (rating[c1] > middle) {
23+
maxCount1++;
24+
}
25+
c1--;
26+
}
27+
28+
let c2 = i + 1;
29+
let maxCount2 = 0;
30+
let minCount2 = 0;
31+
while (c2 < max) {
32+
if (rating[c2] < middle) {
33+
minCount2++;
34+
} else if (rating[c2] > middle) {
35+
maxCount2++;
36+
}
37+
c2++;
38+
}
39+
ans += (minCount1 * maxCount2) + (maxCount1 * minCount2);
40+
}
41+
return ans;
42+
}

0 commit comments

Comments
 (0)