##题目
####Contains Duplicate II
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.
##解题思路
这道题是Contains Duplicate的扩展,但是思路依然很简单,只是判断是否存在两个重复的数字之间的索引间隔是否不大于K。对于HashMap而言,其中key为数字,value为该数组所有的数组中的索引。
##算法代码
代码采用JAVA实现:
1 |
public class { |
近期评论