LeetCode 219 Contains Duplicate II
2015-12-08 16:41
501 查看
题目描述
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.代码
[code] public static boolean containsNearbyDuplicate(int[] nums, int k) { Map<Integer, Integer> map = new HashMap<Integer, Integer>(); for (int i = 0; i < nums.length; i++) { if (map.containsKey(nums[i])) { if (i - map.get(nums[i]) <= k) { return true; } } map.put(nums[i], i); } return false; }
相关文章推荐
- svn无法提交问题,The working copy failed to commit files
- LeetCode 217 Contains Duplicate
- 浅谈RAID写惩罚与IOPS计算[转载]
- UVA 11029 Leading and Trailing
- 事件传递之响应链(Event Delivery: The Responder Chain)【转】
- 游戏AI - 行为树Part2:框架
- 游戏AI - 行为树Part1:简介
- XeTeX: “Failed to convert input string to UTF16″
- LSI MegaRAID(IBM服务器web页面) 8708E SAS RAID卡如何使用手动方式创建RAID5+热备盘
- maven 遇到failOnMissingWebXml有关问题解决方法
- 线程状态的区别 blocked waitting ,join 详解
- 解决 ld: library not found for -xxx linker command failed with exit code 1 (use -v to see invocation)
- wait、waitpid详解
- Failed to install Hi.apk on device ‘emulator-5554′: EOF
- 人工智能系统
- 32位的ane与air sdk升级
- 决绝Capturing 'demo' strongly in this block is likely to lead to a retain cycle
- WebLogic启动报错“Unable to obtain file lock but will retry”
- 【Codeforces Round 271 (Div 2)C】【暴力 坐标变换】Captain Marmot 四个点绕中心旋转 最小步数使得构成正方形
- adb shell之后 ls: openir failed, Permission denied