LeetCode p219 Contains Duplicate II 题解
1.题目:
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 absolute difference between i and j is at most k.
题意:
输入一个数组和最大间隔k,求不超过最大间隔的区间
是否有两个相等的数。
2.解题思路:
维护一个set 见代码
3.代码
1 |
|