Description
Given an array of integers nums, return the number of good pairs. A pair (i, j) is called good if nums[i] == nums[j] and i < j.
Examples
Input:
nums = [1,2,3,1,1,3]Output:
4Explanation:
A 'good pair' requires i < j and nums[i] == nums[j]. The pairs are: (0,3) and (0,4) and (3,4) where nums=1, and (2,5) where nums=3. Total: 4 pairs.
Input:
nums = [1,2,3]Output:
0Explanation:
All elements are distinct, so no good pairs (i, j) with nums[i] == nums[j] exist.
Input:
nums = [5,5,2,2,2]Output:
4Explanation:
There are 4 good pairs: (0,1) where both elements are 5, and (2,3), (2,4), (3,4) where all elements are 2.
Constraints
- •
1 ≤ nums.length ≤ 100