Site icon Wander In Dev

Contains Duplicate (LeetCode #217)

Challenge Statement

Constraints

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.

Exit mobile version