Leetcode Contains Duplicate II
来源:互联网 发布:网络电视能连手机吗 编辑:程序博客网 时间:2024/06/03 23:06
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.
Difficulty: Easy
public class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { if(k == 0) return false; HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); for(int i = 0; i < nums.length; i++){ if(!map.containsKey(nums[i])){ map.put(nums[i], i); } else{ if(Math.abs(map.get(nums[i]) - i) <= k) return true; map.put(nums[i], i); } } return false; }}
0 0
- [LeetCode]Contains Duplicate II
- [LeetCode] Contains Duplicate II
- leetcode Contains Duplicate II
- LeetCode Contains Duplicate II
- [leetcode] Contains Duplicate II
- LeetCode Contains Duplicate II
- 【leetcode】Contains Duplicate II
- leetcode--Contains Duplicate II
- [leetcode]Contains Duplicate II
- [leetCode] Contains Duplicate II
- LeetCode: Contains Duplicate II
- LeetCode Contains Duplicate II
- LeetCode | Contains Duplicate II
- LeetCode Contains Duplicate II
- 【LeetCode】Contains Duplicate II
- leetcode: Contains Duplicate II
- LeetCode Contains Duplicate II
- Leetcode: Contains Duplicate II
- tomcat源码解析(二)--web.xml文件的解析
- 使用p6spy 2监控及打印Spring 4 JdbcTemplate生成的SQL语句
- HTML学习笔记(上)
- Android Studio配置greenDao框架详解--说说那些坑
- Android开发中内存泄露与优化
- Leetcode Contains Duplicate II
- Content-Encoding与Content-Type的区别
- android 6.0 以后 WebView改动
- Quiz 6b_question#7
- ajax(一)
- Linux学习练习之实现小shell
- SpringMVC学习系列(4) 之 数据绑定-1
- 集合类Collection
- RC4密码算法实现