Leetcode - Arrays | Contains Duplicate
217. Contains Duplicate[E]
https://leetcode.com/problems/contains-duplicate/
Description
Given an array of integers, find if the array contains any duplicates.
Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.
Example 1:
1 | Input: [1,2,3,1] |
Example 2:
1 | Input: [1,2,3,4] |
Example 3:
1 | Input: [1,1,1,3,3,4,3,2,4,2] |
Solution
https://leetcode.com/problems/contains-duplicate/solution/
1 | class Solution: |
219. Contains Duplicate II[E]
https://leetcode.com/problems/contains-duplicate-ii/
Description
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.
Example 1:
1 | Input: nums = [1,2,3,1], k = 3 |
Example 2:
1 | Input: nums = [1,0,1,1], k = 1 |
Example 3:
1 | Input: nums = [1,2,3,1,2,3], k = 2 |
Solution
1 | class Solution: |
220. Contains Duplicate III[M]
https://leetcode.com/problems/contains-duplicate-iii/
Description
Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference between nums[i] and nums[j] is at most t and the absolute difference between i and j is at most k.
Example 1:
1 | Input: nums = [1,2,3,1], k = 3, t = 0 |
Example 2:
1 | Input: nums = [1,0,1,1], k = 1, t = 2 |
Example 3:
1 | Input: nums = [1,5,9,1,5,9], k = 2, t = 3 |
Solution
1 |





