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.
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 ≤100nums[i] ≤100Click "Run" to test with sample cases or "Submit" to run all tests.