Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d157b8a

Browse files
committed
add 287
1 parent 0cf93af commit d157b8a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

0287-find-the-duplicate-numer.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
287. Find the Duplicate Number
3+
4+
Submitted: January 5, 2024
5+
6+
Runtime: 63 ms (beats 20.20%)
7+
Memory: 87.86 MB (beats 15.89%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
int findDuplicate(vector<int>& nums) {
13+
unordered_map<int, int> map;
14+
for (const int n : nums) {
15+
map[n]++;
16+
if (map[n] == 2) return n;
17+
}
18+
return 0;
19+
}
20+
};

0 commit comments

Comments
 (0)