src.contains_duplicate

Classes

Solution()

class src.contains_duplicate.Solution[source][source]
containsDuplicate(nums: list[int]) bool[source]

Thought process

  • Create a set to store unique numbers

  • Python set() has O(1) lookup

  • If the number is already in the set, return True

Notes

  • time complexity: O(n)

  • space complexity: O(n)