I was trying to solve problem 1512 on Leet Code, which demands to find all the good pairs of numbers in an array. I wrote code with two functions, but it doesn't work for some reason.
#include <iostream>
using namespace std;
class findthenecessarynumbers(int i,j) {
const int N = 10;
int A[N];
for(int i = 0; i < N; i++)
cin >> A[i];
int seen[N];
for(int i = 0; i < N; i++)
seen[i] = 0;
for(int i = 0; i < N; i++) {
if(seen[i] == 0) {
int count = 0;
for(int j = i; j < N; j++)
if(A[j] == A[i]) {
count += 1;
seen[j] = 1;
}
cout << A[i] << " occurs " << count << " times" << endl;
}
}
return 0;
}
class Solution {
public:
int numIdenticalPairs(int nums[6], int i, int j) {
cin>>i;
cin>>j;
cin>>nums[i];
cin>>nums[j];
if(nums[i] == nums[j] && i<=j)
{
if(nums[i]!=0 || nums[j]!=0)
{
cout<<findthenecessarynumbers(i,j)<<endl;
}
}
else{cout<<0<<endl;}
}
};