219. 存在重复元素 II
1 class Solution 2 { 3 public: 4 bool containsNearbyDuplicate(vector<int>& nums, int k) 5 { 6 unordered_map<int,int> hash; 7 for(int i = 0;i < nums.size();i ++) 8 { 9 if(hash.count(nums[i]) && i - hash[nums[i]] <= k) return true; 10 hash[nums[i]] = i; 11 } 12 return false; 13 } 14 };
Mamba never out

浙公网安备 33010602011771号