Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 09dd2fe

Browse files
committed
Add solution #1512
1 parent 65d7f38 commit 09dd2fe

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

1512-number-of-good-pairs.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* 1512. Number of Good Pairs
3+
* https://leetcode.com/problems/number-of-good-pairs/
4+
* Difficulty: Easy
5+
*
6+
* Given an array of integers nums, return the number of good pairs.
7+
*
8+
* A pair (i, j) is called good if nums[i] == nums[j] and i < j.
9+
*/
10+
11+
/**
12+
* @param {number[]} nums
13+
* @return {number}
14+
*/
15+
var numIdenticalPairs = function(nums) {
16+
const map = new Array(101).fill(0);
17+
return nums.reduce((sum, n) => sum += map[n]++, 0);
18+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
1496|[Path Crossing](./1496-path-crossing.js)|Easy|
235235
1502|[Can Make Arithmetic Progression From Sequence](./1502-can-make-arithmetic-progression-from-sequence.js)|Easy|
236236
1507|[Reformat Date](./1507-reformat-date.js)|Easy|
237+
1512|[Number of Good Pairs](./1512-number-of-good-pairs.js)|Easy|
237238
1550|[Three Consecutive Odds](./1550-three-consecutive-odds.js)|Easy|
238239
1551|[Minimum Operations to Make Array Equal](./1551-minimum-operations-to-make-array-equal.js)|Medium|
239240
1566|[Detect Pattern of Length M Repeated K or More Times](./1566-detect-pattern-of-length-m-repeated-k-or-more-times.js)|Easy|

0 commit comments

Comments
 (0)