Challenge Statement

  • Given an integer array nums, return True if any value appears at least twice in the array and return False if every element is distinct.
  • This challenge corresponds to LeetCode #217.

Constraints

  • 1 <= len(nums) <= 105
  • -109 <= nums[i] <= 109

Example 1:

Input: nums = [1, 2, 3, 1]

Output: True

Example 2:

Input: nums = [1, 2, 3, 4]

Output: False

Example 3:

Input: nums = [1, 1, 1, 3, 3, 4, 3, 2, 4, 2]

Output: True

Solution

Below is my solution and some test cases. This solution has a linear time complexity O(n) and a linear space complexity O(n), where n is the length of the input list nums.