← 返回 meta 的题目列表Check for Duplicate within Range
类型:online_judge
Given an unsorted integer array A, an integer K (window size), and an integer T, determine whether there exist two distinct indices i and j such that A[i] == A[j] and |i - j| <= K. Return true if such elements are found, otherwise return false.
Example 1:
Input: A = [1, 3, 6, 1, 4, 3], K = 5, T = 3
Output: true
Explanation: Element 3 is present at indices 1 and 5 with a distance of 4, which is less than K=5.
Example 2:
Input: A = [2, 4, 1, 2, 5], K = 3, T = 2
Output: false
Explanation: Element 2 is present at indices 0 and 3 with a distance of 3, equal to K=3, but no other pairs meet the condition.
Example
Input
1,3,6,1,4,3
5
3