Contains Duplicate II
来源:互联网 发布:vocaloid软件 编辑:程序博客网 时间:2024/05/17 01:28
Given an array of integers and an integer k, return true if and only if 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> buf; int n = nums.size(); for (int i = 0; i < n; i++) { if (buf.find(nums[i]) != buf.end() && i-buf[nums[i]] <= k) { return true; } else { buf[nums[i]] = i; } } return false; }};
0 0
- Contains Duplicate && Contains Duplicate II
- [LeetCode]Contains Duplicate II
- Contains Duplicate II
- [LeetCode] Contains Duplicate II
- leetcode Contains Duplicate II
- LeetCode Contains Duplicate II
- [leetcode] Contains Duplicate II
- LeetCode Contains Duplicate II
- LeetCode219:Contains Duplicate II
- #219 Contains Duplicate II
- 219. Contains Duplicate II
- 【leetcode】Contains Duplicate II
- leetcode--Contains Duplicate II
- 219Contains Duplicate II
- Contains Duplicate II
- Contains Duplicate II
- Contains Duplicate II
- Leetcode_219 Contains Duplicate II
- Android中的事件传递和消费机制
- CodeForces 542D. Superhero's Job 暴力数论
- 小糖出品:对方法的补充(1)
- BASH
- CodeIgniter的一些实践
- Contains Duplicate II
- 关联android源码
- UIScrollView详解
- Struts2 笔记总结
- 大话23种设计模式
- USACO--3.3Home on the Range+DP
- latex排版编译报错:bibname undefined
- hdoj.1275 两车追及或相遇问题【数学问题】 2015/05/29
- 算法训练 最小乘积(基本型)