-
Notifications
You must be signed in to change notification settings - Fork 2
/
q0219.hpp
40 lines (36 loc) · 842 Bytes
/
q0219.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// q0219.hpp
// LeetCode
//
// Created by NowOrNever on 02/09/2020.
// Copyright © 2020 DoubleL. All rights reserved.
//
#ifndef q0219_hpp
#define q0219_hpp
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <numeric>
#include <stack>
#include <string>
using namespace std;
void question0219(){
class Solution {
public:
bool containsNearbyDuplicate(vector<int>& nums, int k) {
unordered_map<int, int> map;
for (int i = 0; i < nums.size(); i++) {
if (map.find(nums[i]) != map.end() && i - map[nums[i]] <= k){
return true;
}
map[nums[i]] = i;
}
return false;
}
};
}
#endif /* q0219_hpp */