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 ...
随机推荐
- Tornado源码分析 --- Redirect重定向
“重定向”简单介绍: “重定向”指的是HTTP重定向,是HTTP协议的一种机制.当client向server发送一个请求,要求获取一个资源时,在server接收到这个请求后发现请求的这个资源实际存放在 ...
- III USP Freshmen ContestH. MaratonIME gets candies
这题挺有意思的,刚开始不会这交互题,模仿着做了一题就会了,蛮简单 的 这题我用2分,结果wa了,想了一下发现,1到1e9二分50次完全不够用啊,那就转换一下思维,先求出在10^n~10^(n+1)的n ...
- HDU1698 线段树入门之区间修改/查询(lazy标记法)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- 获取div的高度
1.获取div的文档总高度(必须DOM操作): var scrollHeight=document.getElementById("inner").scrollHeight; // ...
- js控制easyui datagrid列的显示和隐藏
easyui datagrid 列隐藏和显示 $('#grid').datagrid('hideColumn','列field'); //把hideColumn换成showColumn 即为显示列
- python的单元测试代码编写流程
单元测试: 单元测试是对单独的代码块分别进行测试, 以确保它们的正确性, 单元测试主要还是由开发人员来做, 其余的集成测试和系统测试由专业的测试人员来做. python的单元测试代码编写主要记住以下几 ...
- Java中替换字符串中特殊字符+ 20150921
需求:今天需要将字符串中的" +"转换程"%2B",但是"+"是正则表达式中的特殊字符,使用需要反斜杠转义,具体示范: String a=& ...
- 使用POI导出Excel(二)-利用模板
一.基本操作见: 使用POI导出Excel 二.本次功能需求 给了一个模板,里面有6个sheet页,每页里面都需要填充相应的数据.如图: 三.需求分析 1.分了6个sheet页,每页的数据都不一样,首 ...
- 宏使用 Tricks
人为地定义一些"无意义"的宏(宏名本身有意义),以起到提升代码程序的可读性. 1. IN/OUT 指定参数用于输入还是输出: #define IN #define OUT void ...
- 博客网站-Hexo+GitHub+Netlify
Hexo+GitHub+Netlify一站式搭建属于自己的博客网站 https://www.cnblogs.com/kerbside/p/10130606.html https://hhongwen. ...