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:4
Explanation:

(0,3),(0,4),(3,4),(2,5).

Input:nums = [1,2,3]
Output:0
Explanation:

All elements are distinct, so no good pairs (i, j) with nums[i] == nums[j] exist.

Input:nums = [5,5,2,2,2]
Output:4
Explanation:

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

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!