public class Solution
{
Dictionary<int, List<int>> dic = new Dictionary<int, List<int>>();
public bool ContainsNearbyDuplicate(int[] nums, int k)
{
for (int i = ; i < nums.Length; i++)
{
var cur = nums[i];
if (!dic.ContainsKey(nums[i]))
{
var list = new List<int>();
list.Add(i);
dic.Add(nums[i], list);
}
else
{
dic[nums[i]].Add(i);
}
} foreach (var d in dic)
{
var list = d.Value;
for (int i = ; i < list.Count - ; i++)
{
if (list[i + ] - list[i] <= k)
{
return true;
}
}
}
return false;
}
}

https://leetcode.com/problems/contains-duplicate-ii/#/description

leetcode219的更多相关文章

  1. LeetCode219:Contains Duplicate II

    Given an array of integers and an integer k, find out whether there there are two distinct indices i ...

  2. [Swift]LeetCode219. 存在重复元素 II | Contains Duplicate II

    Given an array of integers and an integer k, find out whether there are two distinct indices i and j ...

  3. LeetCode--219、268、283、414、448 Array(Easy)

    219. Contains Duplicate II Given an array of integers and an integer k, find out whether there are t ...

  4. 2017-3-11 leetcode 217 219 228

    ji那天好像是周六.....吃完饭意识到貌似今天要有比赛(有题解当然要做啦),跑回寝室发现周日才开始233333 =========================================== ...

  5. LeetCode通关:数组十七连,真是不简单

    分门别类刷算法,坚持,进步! 刷题路线参考:https://github.com/chefyuan/algorithm-base       https://github.com/youngyangy ...

随机推荐

  1. ablout unbuntu default mysql

    http://www.ghostchina.com/how-to-reset-mysqls-root-password/ http://blog.csdn.net/u010603691/article ...

  2. VM虚拟机安装的XP如何全屏

    首先安装install VMwear Tools..,如图:

  3. 【hive】关于用户留存率的计算

    首先用户留存率一般是面向新增用户的概念,是指某一天注册后的几天还是否活跃,是以每天为单位进行计算的.一般收到的需求都是一个时间段内的新增用户的几天留存 (1)找到这个时间段内的新增用户(也可能含有地区 ...

  4. String类的concat()方法

    String类的concat()方法: public class MyClass { public static void main(String[] args) { String str1=&quo ...

  5. 在Jsp中调用静态资源,路径配置问题,jsp获取路径的一些方法

    在Jsp中调用图片.JS脚本等,针对取得的路径有两种调用方式: 1.放入Body中生成绝对路径(不建议) <%@ page language="java" import=&q ...

  6. web service与EJB的区别

    1.WebService可以说是跨平台的,因为它采用的是XML技术,说穿了就是把你的请求按照该WebServece的标准将参数传过去,然后服务器返回结果,当然了最重要的是参数的传递和结果的返回都是采用 ...

  7. 在CMD中使用for命令对单行字符串做分割的方法

    我们都知道CMD中的for命令是执行循环命令的,数据来源可以是一个文件,一个命令的结果或一个字符串,只有这3种来源 如果是一个文件则对这个文件的所有字符串进行循环处理 如果是一个命令结果,那么对这个命 ...

  8. STL标准库-容器-set与multiset

    技术在于交流.沟通,转载请注明出处并保持作品的完整性. set与multiset关联容器 结构如下 set是一种关联容器,key即value,value即key.它是自动排序,排序特点依据key se ...

  9. Mysql查询正在运行的事务以及杀掉它

    查询 正在执行的事务:SELECT * FROM information_schema.INNODB_TRX 根据这个事务的线程ID(trx_mysql_thread_id): 可以使用mysql命令 ...

  10. 接口测试HttpClient实践20150925

    用了工具做接口测试,但是对于加密数据和结果的比对,以及批量数据读取,回头还是觉得代码来更方便灵活,从excle中读取数据,构成参数,发请求,并获取返回结果和预期值比较,并将结果输出程报告,可以深入做成 ...