leetcode-Contains Duplicate II
2015-11-04 20:37
323 查看
Difficulty:
Easy
Given an array of integers and an integer k, find out whether there are two distinct indices
i and j in the array such that nums[i] = nums[j] and the difference between
i and j is at most k.
Easy
Given an array of integers and an integer k, find out whether there are two distinct indices
i and j in the array such that nums[i] = nums[j] and the difference between
i and j is at most k.
class Solution { public: bool containsNearbyDuplicate(vector<int>& nums, int k) { map<int,int> check; int size=nums.size(); for(int i=0;i<size;++i){ if(check.find(nums[i])!=check.end()&&i-check[nums[i]]<=k) return true; check[nums[i]]=i; } return false; } };
相关文章推荐
- Drainage Ditches(最大流)
- LightOJ 1236 Pairs Forming LCM (LCM 唯一分解定理 + 素数筛选)
- saiku - JCR在saiku中的运用原理
- git main branch 提交远程仓库失败
- 使用AIDL实现进程间通信
- Daily Scrumming* 2015.11.4(Day 16)
- process launch failed: Security
- 实战阿里云-实战Fail2Ban之v0.9.3
- 使用mail命令发邮件
- maven3+项目管理命令总结 (错误解决:Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2)
- linux系统监控、诊断工具摘录top IO wait lsof
- httpclient提示Cookie rejected: violates RFC 2109: domain must start with a dot
- 人工智能研究
- Daily Scrum (2015/11/3)
- 多线程wait()和sleep()以及InterruptedException异常
- 1014. Waiting in Line (30)
- 1014. Waiting in Line (30)
- failure during conversion to COFF
- adb remount 失败:remount failed: Operation not permitted
- CONTAINING_RECORD宏的详细解释