For the question: 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.
I wrote the following code:
int numIdenticalPairs(vector<int>& nums) {
int count[102];
for (int num : nums) {
count[num]++;
}
int totalCount = 0;
// Calculate total number of pairs possible
for (int i : count) {
totalCount += ((i) * (i-1))/2;
}
return totalCount;
}
I am getting following error help me fix it:
Line 21: Char 26: runtime error: signed integer overflow: -1844207608 * -1844207609 cannot be represented in type 'int' (solution.cpp) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:30:26