Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions 287. Find the Duplicate Number1
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution {
public:
int findDuplicate(vector<int>& nums) {
int ind = 0;

// sort the vector
sort(nums.begin(),nums.end());
for(int i = 0; i < nums.size() - 1; i++)
{
// if two consecutive elements are equal
// you have find a duplicate
// break the loop
if(nums[i] == nums[i+1])
{
ind = nums[i];
break;
}
}
// return duplicate value
return ind;
}
// for github repository link go to my profile.
};