找出是否存在nums[i]==nums[j],使得 j - i <=k

这是map的一个应用

 class Solution {
public:
bool containsNearbyDuplicate(vector<int>& nums, int k) {
map<int,int> mii;
for (int i = ;i<nums.size() ;++i)
{
if (mii.find(nums[i]) != mii.end())
{
if(i - mii[nums[i]] <= k) return true;
}
mii[nums[i]] = i;
}
return false;
}
};

Leetcode 219 Contains Duplicate II STL的更多相关文章

  1. [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 ...

  2. [LeetCode] 219. Contains Duplicate II ☆(存在重复元素2)

    每天一算:Contains Duplicate II 描述 给出1个整形数组nums和1个整数k,是否存在索引i和j,使得nums[i] == nums[j] 且i和j之间的差不超过k Example ...

  3. 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 ...

  4. LeetCode 219 Contains Duplicate II

    Problem: Given an array of integers and an integer k, find out whether there are two distinct indice ...

  5. 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 ...

  6. (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 ...

  7. Java [Leetcode 219]Contains Duplicate II

    题目描述: Given an array of integers and an integer k, find out whether there are two distinct indices i ...

  8. C#解leetcode 219. Contains Duplicate II

    该题用到了.NET 3.5在System.Collections.Generic命名空间中包含一个新的集合类:HashSet<T>的Add()方法,详细信息请看转载:C# HashSet ...

  9. [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 ...

随机推荐

  1. c#Winform控件总结

    1. C# WinForm控件.自定义控件整理(大全) (http://www.cnblogs.com/top5/archive/2010/04/29/1724039.html) 2. c#窗体控件用 ...

  2. Java获取服务器网址

    StringBuffer url1 = request.getRequestURL(); String tempContextUrl1 = url1.delete(url1.length() - re ...

  3. java动态加载类和静态加载类笔记

    JAVA中的静态加载类是编译时刻加载类  动态加载类指的是运行时刻加载类 二者有什么区别呢 举一个例子  现在我创建了一个类  实现的功能假设为通过传入的参数调用具体的类和方法 class offic ...

  4. SQLServer 脚本测试

    最近在做大数据同步的工作.很少数据需要特殊清洗算法,每次测试,都测试全部数据,浪费时间,可以只测试那些特殊数据即可(切记).

  5. IOS AFNetworking配置进IOS

    Prefix Header 中填入绝对路径 //PCH 里面加入这个写代码 #ifndef TARGET_OS_IOS #pragma mark ---------- for AFNetwork st ...

  6. ListView中的item的按照和item点击事件并存

    整个xml文件的根元素如LinearLayout中添加属性android:descendantFocusability="blocksDescendants"

  7. 【java】:通用接口

    电商接口 京东获取单个商品价格接口: http://p.3.cn/prices/mgets?skuIds=J_商品ID&type=1 用例 ps:商品ID这么获取:http://item.jd ...

  8. Silverlight C1.Silverlight.FlexGrid 表格动态列

    很多时候,我们对于表格展示的数据,需要根据条件不停的变化,这就需要表格列能动态生成,即没有Model的概念(万物始于无形).先上主要代码: 一.根据参数绑定列定义 二.根据数据动态创建数据对象,并添加 ...

  9. .net web获取自己的ip地址

    using System;using System.Text;using System.Web;using System.Text.RegularExpressions; namespace MxWe ...

  10. linux用户、组管理及权限(一)

    一.用户管理 1.为什么需要用户 1)计算机及网络资源的合理分配  2)可以控制用户访问系统的权限.3)身份认证 4) 进程 以某个用户的身份来运行 2.用户分类 用户的角色是通过UID(用户ID)来 ...