leetcode219
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的更多相关文章
- LeetCode219:Contains Duplicate II
Given an array of integers and an integer k, find out whether there there are two distinct indices i ...
- [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 ...
- 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 ...
- 2017-3-11 leetcode 217 219 228
ji那天好像是周六.....吃完饭意识到貌似今天要有比赛(有题解当然要做啦),跑回寝室发现周日才开始233333 =========================================== ...
- LeetCode通关:数组十七连,真是不简单
分门别类刷算法,坚持,进步! 刷题路线参考:https://github.com/chefyuan/algorithm-base https://github.com/youngyangy ...
随机推荐
- hdu4965矩阵快速幂
这题不能直接按常规做啊,因为数组根本就开不下,转换思维A(B*A)^(n*n-1)B 这样的话数组B*A就是10*10了,然后快速幂就行了 刚开始数组都开小了,tle,还找了半天bug...还有就是定 ...
- UVA-129 Krypton Factor(回溯)
题目大意:由字母A到Z组成的字符串,其中有两个子串完全相同的叫做容易的串,反之叫困难的串.找出由前L个字母组成的第n个困难的串. 题目分析:简单回溯,不过要判断是否存在重复子串比较棘手.<入门经 ...
- CF 160D Edges in MST 最小生成树的性质,寻桥,缩点,批量处理 难度:3
http://codeforces.com/problemset/problem/160/D 这道题要求哪条边存在于某个最小生成树中,哪条边不存在于最小生成树中,哪条边绝对存在于最小生成树中 明显桥边 ...
- iOS笔记之网络
用POST方式上传数据时,数组怎么处理? NSError *error; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data ...
- Jenkins插件开发(一)--环境搭建
最近写了一个jenkins插件,功能比较简单,时间主要是花在对jenkins插件框架和Maven的熟悉上.jenkins插件虽然以前也接触过一点,不过现在都忘得差不多了,这个笔记权当知识点记录,顺带介 ...
- java基础第10天
Java异常 Exception 异常指的的在运行期出现的错误,在编译阶段出现的语法错误等,不能称之为异常. 编译类异常 必须处理之后才能正常编译(类找不到,IO异常,在API文档中明确写明throw ...
- CF1082G:G. Petya and Graph(裸的最大闭合权图)
Petya has a simple graph (that is, a graph without loops or multiple edges) consisting of n n vertic ...
- 《DSP using MATLAB》Problem 2.4
生成并用stem函数画出这几个序列. 1.代码: %% ------------------------------------------------------------------------ ...
- memsql filesystem pipeline 试用
一些功能类似drill ,比如s3,file ... 创建file pipeline 准备file mkdir -p /opt/db/ touch books.txt 内容如下: The Catche ...
- 64位windows 2003和windows xp
msdn windows2003 64位简体中文企业版R2 sp2(cn_win_srv_2003_r2_enterprise_x64_with_sp2_vl) ed2k://|file|cn_win ...