File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 234
234
1496|[ Path Crossing] ( ./1496-path-crossing.js ) |Easy|
235
235
1502|[ Can Make Arithmetic Progression From Sequence] ( ./1502-can-make-arithmetic-progression-from-sequence.js ) |Easy|
236
236
1507|[ Reformat Date] ( ./1507-reformat-date.js ) |Easy|
237
+ 1512|[ Number of Good Pairs] ( ./1512-number-of-good-pairs.js ) |Easy|
237
238
1550|[ Three Consecutive Odds] ( ./1550-three-consecutive-odds.js ) |Easy|
238
239
1551|[ Minimum Operations to Make Array Equal] ( ./1551-minimum-operations-to-make-array-equal.js ) |Medium|
239
240
1566|[ Detect Pattern of Length M Repeated K or More Times] ( ./1566-detect-pattern-of-length-m-repeated-k-or-more-times.js ) |Easy|
You can’t perform that action at this time.
0 commit comments