File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
number-of-unequal-triplets-in-array Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ Step 2. Add the dependency
45
45
46
46
<summary >展开查看</summary >
47
47
48
+ https://leetcode.cn/problems/number-of-unequal-triplets-in-array
49
+
48
50
https://leetcode.cn/problems/find-the-city-with-the-smallest-number-of-neighbors-at-a-threshold-distance/
49
51
50
52
https://leetcode.cn/problems/champagne-tower
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments