Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitca02c83

Browse files
committed
Add solution #2475
1 parentc2cb1f0 commitca02c83

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#1,970 LeetCode solutions in JavaScript
1+
#1,971 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1866,6 +1866,7 @@
18661866
2469|[Convert the Temperature](./solutions/2469-convert-the-temperature.js)|Easy|
18671867
2471|[Minimum Number of Operations to Sort a Binary Tree by Level](./solutions/2471-minimum-number-of-operations-to-sort-a-binary-tree-by-level.js)|Medium|
18681868
2472|[Maximum Number of Non-overlapping Palindrome Substrings](./solutions/2472-maximum-number-of-non-overlapping-palindrome-substrings.js)|Hard|
1869+
2475|[Number of Unequal Triplets in Array](./solutions/2475-number-of-unequal-triplets-in-array.js)|Easy|
18691870
2482|[Difference Between Ones and Zeros in Row and Column](./solutions/2482-difference-between-ones-and-zeros-in-row-and-column.js)|Medium|
18701871
2490|[Circular Sentence](./solutions/2490-circular-sentence.js)|Easy|
18711872
2493|[Divide Nodes Into the Maximum Number of Groups](./solutions/2493-divide-nodes-into-the-maximum-number-of-groups.js)|Hard|
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* 2475. Number of Unequal Triplets in Array
3+
* https://leetcode.com/problems/number-of-unequal-triplets-in-array/
4+
* Difficulty: Easy
5+
*
6+
* You are given a 0-indexed array of positive integers nums. Find the number of
7+
* triplets (i, j, k) that meet the following conditions:
8+
* - 0 <= i < j < k < nums.length
9+
* - nums[i], nums[j], and nums[k] are pairwise distinct.
10+
* - In other words, nums[i] != nums[j], nums[i] != nums[k], and nums[j] != nums[k].
11+
*
12+
* Return the number of triplets that meet the conditions.
13+
*/
14+
15+
/**
16+
*@param {number[]} nums
17+
*@return {number}
18+
*/
19+
varunequalTriplets=function(nums){
20+
constmap=newMap();
21+
for(constnumofnums){
22+
map.set(num,(map.get(num)||0)+1);
23+
}
24+
25+
letresult=0;
26+
letleft=0;
27+
consttotal=nums.length;
28+
29+
for(constcountofmap.values()){
30+
constright=total-count-left;
31+
result+=left*count*right;
32+
left+=count;
33+
}
34+
35+
returnresult;
36+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp