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:
(0,3),(0,4),(3,4),(2,5).
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