PIXELBANKv8.2.1
Menu

Contains Duplicate

Given an integer array nums, return True if any value appears at least twice in the array, and False if every element is distinct.

Example:

Input:
1,2,3,1
Output:
True
Reasoning:
  • We start by iterating over the input array: [1, 2, 3, 1]
  • As we iterate, we keep track of the elements we've seen so far
  • When we encounter the second 1, we realize it's a duplicate, since we've seen it before: 1[1,2,3]1 \in [1, 2, 3]
  • The presence of a duplicate immediately returns True, indicating that the array contains at least one value that appears twice
  • The final output is therefore: True

Constraints:

  • 1 <= len(nums) <= 10^5
  • -10^9 <= nums[i] <= 10^9
Editor

Test Results

0/0
Run code to see test results.