Skip to content

Commit 793b951

Browse files
authored
Create 287.cpp
1 parent dc71942 commit 793b951

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

leetcode/cpp/Array/287.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
int findDuplicate(vector<int>& nums) {
4+
map<int,int> x;
5+
int ans;
6+
for(int i=0;i<nums.size();i++)
7+
{
8+
x[nums[i]]++;
9+
if(x[nums[i]]>1)
10+
{
11+
ans=nums[i];
12+
}
13+
}
14+
return ans;
15+
}
16+
};

0 commit comments

Comments
 (0)