#219
Contains Duplicate II
pupil · 480 · lc easy +27 · verified · 50.9% accepted · 7,437 likes · top 39%
Description
Determine whether there exist two indices i and j in nums (with i != j) where the values are equal and the distance between indices is at most k.
Example 1:
Input: nums = [1,2,3,1], k = 3
Output: true
Example 2:
Input: nums = [1,0,1,1], k = 1
Output: true
Example 3:
Input: nums = [1,2,3,1,2,3], k = 2
Output: false
Code
1
2
3