leetcode
question link
Help me out in this problem
yeah , what issue u r facing?
class Solution {
public:
int findDuplicate(vector<int>& ar)
{
map<int,int> mp;
int n=ar.size();
for(int i=0;i<n;i++)
{
mp[ar[i]]=0;
}
for(int i=0;i<n;i++)
{
if(mp[ar[i]]==0)
{
mp[ar[i]]=1;
}
else
{
return ar[i];
}
}
return -1; // it will never run,just to surpass warning i m adding this
}
};
i am getting error but i did able to debug it?
@why is it so can you tell me
without return statement compiler will think that function return type is int but we r not returning anything , hence it will raise error.
@aman212yadav ee in question it is given it always contain duplictes then else part will definitely run in each case