leetCode(28):Contains Duplicate II
2024-08-27 09:37:09
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;
}
};
最新文章
- Ubuntu14.04安装MySql
- 数据库收缩:NOTRUNCATE与TRUNCATEONLY
- ie8 不支持new Date(&#39;2012-11-10&#39;)
- Matlab神经网络工具箱学习之一
- Hadoop2.4代码的坑
- 淘宝对接API
- leetcode算法刷题(三)
- haproxy+tomcat集群搭建
- jmeter 实现登录一次,多次操作登录后的某一个功能
- bootstrap 栅格系统 自动隐藏
- JVM内部原理
- USB有时adb shell连不上设备
- C# 中将月份格式化为英语缩写格式
- Python 包内的导入问题(绝对导入和相对导入)
- day 12
- ABP框架系列之四十三:(OData-Integration-OData集成)
- R2 day2
- 两个DIV并排显示
- 如何在Visual Studio 2013中连接中国版的Azure
- 关Java的内存模型(JMM)
热门文章
- hdu 3573(数学+贪心)
- JMeter -----响应时间设置
- Delphi idHttpServer接收Http Get请求解码问题
- day3修改配置文件
- 二安装Python
- cordova 使用WKWebView 适配iphoneX及解决不能拨打电话问题
- 洛谷P1438 无聊的数列 [zkw线段树]
- 自定义寄存器出现error C142: &#39;SFR&#39;: invalid base address
- Unity 游戏开发技巧集锦之使用忍者飞镖创建粒子效果
- 解释Crypto模块怎么就这么";皮";?No module named ";Crypto";