Loading...
You are given an integer array nums. An index pair (i, j) counts when i < j and nums[i] == nums[j]: two different positions hold the same value.
nums
(i, j)
i < j
nums[i] == nums[j]
Return the total number of such index pairs.
Input: nums = [1,2,3,1,1,3] Output: 4 Explanation: The qualifying index pairs are (0,3), (0,4), and (3,4) for value 1, plus (2,5) for value 3.
Input: nums = [1,1,1,1] Output: 6 Explanation: All four values are equal, so every one of the 6 index pairs qualifies.
Input: nums = [1,2,3] Output: 0 Explanation: All values are distinct, so no index pair qualifies.
nums.length
nums[i]