Created
October 6, 2024 17:32
-
-
Save mohneesh7/0876acfc2814a73e27620da09c1ebb2b to your computer and use it in GitHub Desktop.
Solution for Contains Duplicate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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