-
Notifications
You must be signed in to change notification settings - Fork 0
219_ContainsDuplicateII
a920604a edited this page Apr 14, 2023
·
1 revision
class Solution {
public:
bool containsNearbyDuplicate(vector<int>& nums, int k) {
int n = nums.size();
unordered_map<int, int> mp;
for(int i=0;i<n;++i){
if(mp.count(nums[i])){
if(( i - mp[nums[i]])<=k) return true;
}
mp[nums[i]] = i;
}
return false;
}
};
- time complexity
O(nlogn)
- speed complexity
O(n)
footer