Given an array of integers and an integer k,
find out whether there there are two distinct indices i and j in
the array such that nums[i] = nums[j] and
the difference between iand j is
at most k.

哈希表的使用

class Solution {
public:
bool containsNearbyDuplicate(vector<int>& nums, int k) {
map<int,int> value;
for(int i=0;i<nums.size();++i)
{
if(value.find(nums[i])!=value.end() && i-value[nums[i]]<=k)
return true;
value[nums[i]]=i;
}
return false;
}
};

最新文章

  1. Ubuntu14.04安装MySql
  2. 数据库收缩:NOTRUNCATE与TRUNCATEONLY
  3. ie8 不支持new Date(&#39;2012-11-10&#39;)
  4. Matlab神经网络工具箱学习之一
  5. Hadoop2.4代码的坑
  6. 淘宝对接API
  7. leetcode算法刷题(三)
  8. haproxy+tomcat集群搭建
  9. jmeter 实现登录一次,多次操作登录后的某一个功能
  10. bootstrap 栅格系统 自动隐藏
  11. JVM内部原理
  12. USB有时adb shell连不上设备
  13. C# 中将月份格式化为英语缩写格式
  14. Python 包内的导入问题(绝对导入和相对导入)
  15. day 12
  16. ABP框架系列之四十三:(OData-Integration-OData集成)
  17. R2 day2
  18. 两个DIV并排显示
  19. 如何在Visual Studio 2013中连接中国版的Azure
  20. 关Java的内存模型(JMM)

热门文章

  1. hdu 3573(数学+贪心)
  2. JMeter -----响应时间设置
  3. Delphi idHttpServer接收Http Get请求解码问题
  4. day3修改配置文件
  5. 二安装Python
  6. cordova 使用WKWebView 适配iphoneX及解决不能拨打电话问题
  7. 洛谷P1438 无聊的数列 [zkw线段树]
  8. 自定义寄存器出现error C142: &#39;SFR&#39;: invalid base address
  9. Unity 游戏开发技巧集锦之使用忍者飞镖创建粒子效果
  10. 解释Crypto模块怎么就这么&quot;皮&quot;?No module named &quot;Crypto&quot;