博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Contains Duplicate II
阅读量:4614 次
发布时间:2019-06-09

本文共 659 字,大约阅读时间需要 2 分钟。

Description:

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 i and j is at most k.

Code:

1  bool containsNearbyDuplicate(vector
& nums, int k) { 2 unordered_map
m; 3 int n = nums.size(); 4 for (int i = 0; i < n; ++i) 5 { 6 if ( m.count(nums[i]) && i - m[nums[i]] <= k) 7 return true; 8 else 9 m[nums[i]] = i;10 }11 return false;12 }

 

转载于:https://www.cnblogs.com/happygirl-zjj/p/4604850.html

你可能感兴趣的文章
City Upgrades
查看>>
“人少也能办大事”---K2 BPM老客户交流会
查看>>
关于七牛进行图片添加文字水印操作小计
查看>>
DataSource数据库的使用
查看>>
CentOS开启samba实现文件共享
查看>>
MSSQL使用sqlbulkcopy批量插入数据
查看>>
证明一个数能被3整除,当且仅当它的各位数的和能被3整除
查看>>
2018秋寒假作业4—PTA编程总结1
查看>>
android自适应屏幕
查看>>
2019-北航面向对象-电梯作业总结
查看>>
SqlHelper
查看>>
初识算法、数据结构
查看>>
Luogu4069 SDOI2016 游戏 树链剖分、李超线段树
查看>>
Java的内部类真的那么难以理解?
查看>>
一文搞懂Java环境,轻松实现Hello World!
查看>>
hash实现锚点平滑滚动定位
查看>>
也谈智能手机游戏开发中的分辨率自适应问题
查看>>
【转】MYSQL数据库设计规范与原则
查看>>
《中国大历史》—— 读后总结
查看>>
回溯法算法框架
查看>>