找出是否存在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. PHP--目录处理

    __file___ dirname(): dirname()与__file__的组合:dirname(__file__)

  2. Eclipse: Launch failed. Binary not found

    最近写demo出现这个问题, 然后上网搜了一会儿, 最后发现只要点击eclipse上的锤子图标就可以了.

  3. Azure china服务状态报告查看网址

    https://www.azure.cn/support/service-dashboard/

  4. UWP深入学习二:各种激活方式

    Launching, resuming, and multitasking How to launch an app for results Auto-launching with file and ...

  5. 【筛法求素数】【质因数分解】bzoj2721 [Violet 5]樱花

    http://www.cnblogs.com/rausen/p/4138233.html #include<cstdio> #include<iostream> using n ...

  6. linux ntp 服务器和用户端

    ntp 服务器 1.输入 rpm -qa|grep ntp 查看是否安装了ntp服务器 2.如果没安装 yum -y install ntp 安装 3.修改 /etc/ntp.conf 将原serve ...

  7. mybatis异常

    一.Invalid bound statement 1.mapper.xml中namespaces错误(***) 2.方法不存在 3.方法返回值错误 二.Mapped Statements colle ...

  8. RHEL5.8设置OpenSSH的X11 Forwarding功能

    X11的Forwarding功能需要在SSH中进行设置,RedHat Enterprise Linux5.8默认使用的而是OpenSSH,现将设置方法记录如下: OpenSSH配置文件路径: /etc ...

  9. Orchard Express Oracle v1.7.2 发布

    发布说明: 1. 添加Oracle支持,在AppData目录下提供Oracle及Sql Server数据库创建脚本. 2. 修正上一版本(精简版 v1.7.2)中,Dashboard无需登录问题. O ...

  10. 【原创】注册assembly 到GAC

    http://msdn.microsoft.com/en-us/library/dkkx7f79.aspx http://stackoverflow.com/questions/2182316/how ...