Contains Duplicate

Write the code, see it run, pass the checks.

The problem

  • easy
  • Code

Write hasDuplicate(nums): return true if any number appears more than once in nums, and false if every number is different. An empty list or a single number has no duplicates. You may reorder nums if that helps. For example, hasDuplicate([1, 2, 3, 1]) is true and hasDuplicate([1, 2, 3, 4]) is false. The checks include 100,000 numbers, so comparing every pair is too slow.

Your code must pass

  • Finds a number that appears twice
  • Returns false when every number is different
  • Returns false for an empty list or a single number
  • Is fast enough for 100,000 numbers