leetCode(28):Contains Duplicate II
Given an array of integers and an integer k,
 find out whether there there are two distinct indices i and j in
 the array such that nums[i] = nums[j] and
 the difference between iand j is
 at most k.
哈希表的使用
class Solution {
public:
    bool containsNearbyDuplicate(vector<int>& nums, int k) {
        map<int,int> value;
    	for(int i=0;i<nums.size();++i)
    	{
    		if(value.find(nums[i])!=value.end()  &&  i-value[nums[i]]<=k)
    			return true;
    		value[nums[i]]=i;
    	}
    	return false;
    }
};
leetCode(28):Contains Duplicate II的更多相关文章
- [LeetCode] 219. Contains Duplicate II 包含重复元素 II
		Given an array of integers and an integer k, find out whether there are two distinct indices i and j ... 
- [LeetCode] 219. Contains Duplicate II ☆(存在重复元素2)
		每天一算:Contains Duplicate II 描述 给出1个整形数组nums和1个整数k,是否存在索引i和j,使得nums[i] == nums[j] 且i和j之间的差不超过k Example ... 
- python leetcode 日记 --Contains Duplicate II --219
		题目: Given an array of integers and an integer k, find out whether there are two distinct indices i a ... 
- LeetCode 219. 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 Contains Duplicate II
		Problem: Given an array of integers and an integer k, find out whether there are two distinct indice ... 
- Java for LeetCode 219 Contains Duplicate II
		Given an array of integers and an integer k, find out whether there there are two distinct indices i ... 
- Leetcode 219 Contains Duplicate II STL
		找出是否存在nums[i]==nums[j],使得 j - i <=k 这是map的一个应用 class Solution { public: bool containsNearbyDuplic ... 
- (easy)LeetCode  219.Contains Duplicate II
		Given an array of integers and an integer k, find out whether there there are two distinct indices i ... 
- Java [Leetcode 219]Contains Duplicate II
		题目描述: Given an array of integers and an integer k, find out whether there are two distinct indices i ... 
随机推荐
- jquery.query.js 插件(示例及简单应用) —— html之间传值
			帮助文档 var url = location.search; > "?action=view§ion=info&id=123&debug&te ... 
- jmeter-----用户参数和用户定义变量的区别
			在调试脚本的时候,可以使用前置处理器中的用户参数组件进行数据的提供,在该数据中可以使用固定值也可以使用变量值. 如果是固定不变的一些配置项,不需要多个值的时候,也可以使用用户已定义的变量组件. 一.界 ... 
- 常用 Java Profiling 工具的分析与比较
			转自:http://www.ibm.com/developerworks/cn/java/j-lo-profiling/index.html 在 Java 程序的开发过程中,不可避免地会遇到内存使用. ... 
- bzoj 1898 矩阵快速幂
			思路:因为鱼的周期为2, 3, 4, 所以以12个为周期,我们拿走12步得到的矩阵进行快速幂,余下的再进行一次矩阵乘法. #include<bits/stdc++.h> #define L ... 
- 【SQL SERVER】T-SQL 字符串前加 N 是什么意思
			比如 select @status = N'stopped' 那么其中的字符串 stopped 前面为什么要加 N 呢?而且我们发现有些地方加 N 与否都没有影响,有些地方又必须加 N. N 在这里表 ... 
- 验证码无法显示:Could not initialize class sun.awt.X11GraphicsEnvironment 解决方案
			一.原因现象:图下图 二.原因导致: 经过Google发现很多人也出现同样的问题.从了解了X11GraphicEnvironment这个类的功能入手,一个Java服务器来处理图片的API基本上是需要运 ... 
- Java常用工具类之发送邮件
			package com.csice.utils; import java.io.File; import java.io.FileInputStream; import java.io.FileNot ... 
- 【2-SAT】The Ministers’ Major Mess UVALive – 4452
			题目链接:https://cn.vjudge.net/contest/209474#problem/C 题目大意: 一共有m个提案,n个政客,每个政客都会对一些提案(最多四个)提出自己的意见——通过或 ... 
- 工厂bean和bean工厂
			FactoryBean(工厂bean):是bean的加工工厂,是对已知Bean的加工,是一个接口,要实现三个方法: ① Object getObject()可以对bean进行加工添加功能. ② Cla ... 
- Ubuntu16.04安装mongodb 及使用
			1.导入软件源的公钥 sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 2.为mongodb创建软件 ... 
