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. bzoj-4887-dp+矩阵快速幂

    4887: [Tjoi2017]可乐 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 247  Solved: 170[Submit][Status][D ...

  2. HDU 4842 距离压缩DP

    过河 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submissi ...

  3. 047——VUE中css过渡动作实例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0

    Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3510   Accepted:  ...

  5. SSH使用主机名访问

    比如说A电脑已经和B电脑实现了ssh免密码登陆!但是A电脑通过 ssh B电脑的主机名称 不行! 解决办法: 01.修改A电脑中的hosts文件    vim /etc/hosts 02.进入编辑界面 ...

  6. 表单验证jq.validate.js

    源代码--demo Validate:function(){ var me=this; var $form = $('#form'); //添加自定义方法: 同时验证手机和座机电话    jQuery ...

  7. nginx详细应用

    一.nginx的基本功能 基本Http服务,可以作为Http代理服务器和反向代理服务器,支持通过缓存加速访问,可以完成简单的负载均衡和容错,支持包过滤功能,支持SSL 高级Http服务,可以进行自定义 ...

  8. opencv:基于颜色空间的肤色检测方法

    参考链接:https://www.cnblogs.com/skyfsm/p/7868877.html

  9. I.MX6 Manufacturing Tool V2 (MFGTool2) ucl2.xml hacking

    <!-- * Copyright (C) 2010-2013, Freescale Semiconductor, Inc. All Rights Reserved. * The CFG elem ...

  10. 毕业了-java二叉树层次遍历算法

    /*************************************** * 时间:2017年6月23日 * author:lcy * 内容:二叉树的层次遍历 * 需要借助队列这个数据结构,直 ...