Skip to content

Instantly share code, notes, and snippets.

@mohneesh7
Created October 6, 2024 17:32
Show Gist options
  • Save mohneesh7/0876acfc2814a73e27620da09c1ebb2b to your computer and use it in GitHub Desktop.
Save mohneesh7/0876acfc2814a73e27620da09c1ebb2b to your computer and use it in GitHub Desktop.
Solution for Contains Duplicate
# Solution for Contains Duplicate
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
# import numpy as np
# from collections import Counter
# counter = Counter(nums)
# for x in counter:
# if counter[x] > 1:
# return True
# return False
# above approach is taking 437 ms too slow.
return (len(set(nums)) != len(nums)) # still takes 404 ms
# return ( len(np.unique(nums)) != len(nums)) # takes 613 ms useless using numpy here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment