We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 10d2fbf + 8bd1844 commit 32f3f53Copy full SHA for 32f3f53
cpp/219-Contains-Duplicate-II.cpp
@@ -0,0 +1,15 @@
1
+class Solution {
2
+public:
3
+ bool containsNearbyDuplicate(vector<int>& nums, int k) {
4
+ unordered_map<int,int> number_map;
5
+ for (int i = 0; i < nums.size(); ++i) {
6
+ int num = nums[i];
7
+ if (number_map.find(num) != number_map.end() && i - number_map[num] <= k) {
8
+ return true;
9
+ }else {
10
+ number_map[num] = i;
11
+ }
12
13
+ return false;
14
15
+};
0 commit comments