Back to course home
0% completed
Vote For New Content
Contains Duplicate II (easy)
Problem Statement
Given an array of integers nums
and an integer k
, return true
if there are any two different indices i
and j
in the array where nums[i] == nums[j]
and abs(i - j) <= k
. Otherwise, return false
.
Examples
Example 1:
- Input:
nums = [10, 20, 10, 30], k = 1
- Output:
false
- Explanation: The number
10
appears at positions0
and2
. The difference between these positions is2
, which is not less thank
.
Example 2:
- Input:
nums = [5, 15, 25, 5, 35], k = 3
- Output:
true
- Explanation: The number `5
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page