We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1475f55 commit f4903fcCopy full SHA for f4903fc
README.md
@@ -10,6 +10,8 @@ leetcode 测试
10
11
##### 包含的内容如下
12
13
+https://leetcode.cn/problems/number-of-good-pairs
14
+
15
https://leetcode.cn/problems/count-unique-characters-of-all-substrings-of-a-given-string
16
17
https://leetcode.cn/problems/minimum-height-tree-lcci/
number-of-good-pairs/index.ts
@@ -0,0 +1,11 @@
1
+export default function numIdenticalPairs(nums: number[]): number {
2
+ const cnt = new Map<number, number>();
3
+ for (const num of nums) {
4
+ cnt.set(num, (cnt.get(num) ?? 0) + 1);
5
+ }
6
+ const ans = Array.from(cnt.values()).reduce(
7
+ (a, v) => a + Math.floor((v * (v - 1)) / 2),
8
+ 0
9
+ );
+ return ans;
+}
0 commit comments