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. php--------网页开发实现微信JS的(定位,地图显示,照片选择功能)

    今天说说微信网页开发中一下JS的功能,分享一下,希望对各位有所帮助. 前提:要有公众号,和通过微信认证,绑定域名,得到相应信息,appid,appsecret等. 微信开发文档:https://mp. ...

  2. 2-14-1 MySQL基础语句,查询语句

    一. SQL概述 结构化查询语言(Structured Query Language)简称SQL 1. 它是一种特殊目的的编程语言 2. 它还是一种数据库查询和程序设计语言 (用于存取数据以及查询.更 ...

  3. HIVE从路人到入门

    绪论 第一章 Hive的基本架构及原理 第二章 基础知识 第三章 基本操作 第四章 复杂操作 总结

  4. 向多页TABLE中插入数据时,新增行总是在当前页的最后一行

    CODE IN CO OATableBean table = (OATableBean)webBean.findChildRecursive("LineTable"); int n ...

  5. 使用springfox+swagger2书写API文档(十八)

    使用springfox+swagger2书写API文档 springfox是通过注解的形式自动生成API文档,利用它,可以很方便的书写restful API,swagger主要用于展示springfo ...

  6. jdk1.8的lambda语法(转)

    原文链接:http://www.jb51.net/article/115081.htm 代码: package com.jdk_8; import org.junit.Test; import jav ...

  7. Eclipse 项目有红惊叹号

    Eclipse 项目有红感叹号原因:显示红色感叹号是因为jar包的路径不对 解决:在项目上右击Build Path -> Configure Build Paht...(或Propertise- ...

  8. PyalgoTrade 绘图(七)

    PyAlgoTrade使得绘制策略执行变得非常简单 from pyalgotrade import strategy from pyalgotrade.technical import ma from ...

  9. Map集合统计字母次数

    Map集合练习:"asfefxAAcf34vrfdfse2-2asd--wdd"获取该字符串中,每一个字母出现的次数要求打印的结果是:a(2)c(1)...;思路:对结果分析发现, ...

  10. Struts2自定义标签3模仿原有的s:if s:elseif s:else自定义自己的if elsif else

    第一步:webroot/web-inf下简历str.tld文件 <?xml version="1.0" encoding="UTF-8"?> < ...