Given an integer array nums, return true if any value appears more than once in the array, otherwise return false.
Example 1:
Input: nums = [1, 2, 3, 3]
Output: true
Example 2:
Input: nums = [1, 2, 3, 4]
Output: false
In [12]:
def hasDuplicate(nums):
myset=set()
for num in nums:
if num not in myset:
myset.add(num)
else:
return True
return False
In [13]:
print(hasDuplicate([1, 2, 3, 4]))
False
In [14]:
print(hasDuplicate([1, 2, 3, 3]))
True
In [ ]: