Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Solution
- {
- public bool ContainsNearbyDuplicate(int[] nums, int k)
- {
- // value, index
- var dict = new Dictionary<int, int>();
- for (var index = 0; index < nums.Length; index++)
- {
- var i = nums[index];
- if (dict.ContainsKey(i))
- {
- if (index - dict[i] <= k)
- return true;
- dict[i] = index;
- }
- else
- {
- dict.Add(i, index);
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement