Skip to content

Commit 1e15414

Browse files
committed
https://leetcode.cn/problems/number-of-unequal-triplets-in-array
1 parent d980150 commit 1e15414

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Step 2. Add the dependency
4545

4646
<summary>展开查看</summary>
4747

48+
https://leetcode.cn/problems/number-of-unequal-triplets-in-array
49+
4850
https://leetcode.cn/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/
4951

5052
https://leetcode.cn/problems/champagne-tower
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default function unequalTriplets(nums: number[]): number {
2+
nums.sort((a, b) => a - b);
3+
4+
let ans = 0;
5+
let start = 0;
6+
const n = nums.length;
7+
for (let i = 0; i < n - 1; i++) {
8+
const x = nums[i];
9+
if (x != nums[i + 1]) {
10+
ans += start * (i - start + 1) * (n - 1 - i);
11+
start = i + 1;
12+
}
13+
}
14+
return ans;
15+
}

0 commit comments

Comments
 (0)