Contains Duplicate

easy · array, set, hash-map

Contains Duplicate

Given an integer array nums, return true if any value appears at least twice, and false if every element is distinct.

Function signature

func ContainsDuplicate(nums []int) bool

Example

nums = [1,2,3,1]
output = true

Constraints

  • 0 <= len(nums) <= 200_000
  • -1_000_000_000 <= nums[i] <= 1_000_000_000

Notes

  • Aim for O(n) time using a set/hash map.
Run tests to see results
No issues detected