algos_and_structures/neetcode/duplicate_integer/main.py
2024-11-02 14:03:30 +03:00

28 lines
638 B
Python

from typing import List
class Solution:
def hasDuplicate(self, nums: List[int]) -> bool:
if len(nums) == 0:
return False
res = dict()
for entry in nums:
is_dublicate = res.get(entry)
if is_dublicate:
return True
res[entry] = True
return False
input_1 = [1, 2, 3, 3]
input_2 = [1, 2, 3, 4]
input_3 = []
input_4 = [0]
input_5 = [1, 2, 2, 2, 2, 3, 1, 1]
sol = Solution()
print(sol.hasDuplicate(input_1))
print(sol.hasDuplicate(input_2))
print(sol.hasDuplicate(input_3))
print(sol.hasDuplicate(input_4))
print(sol.hasDuplicate(input_5))