You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
5
-
'''
6
-
# Performance
7
-
'''
8
-
Runtime: 96 ms, faster than 93.53% of Python3 online submissions for Contains Duplicate II.
9
-
Memory Usage: 20.5 MB, less than 62.50% of Python3 online submissions for Contains Duplicate II.
10
-
'''
11
-
12
-
# Algorithm Explained
13
-
'''
14
-
Create a hashmap to remember the most recent position of unique values
15
-
If we found duplicate and the range is less than k, then return true
16
-
Else remember that index
17
-
18
-
Space: O(n) with n is the number of original array
0 commit comments