I´m trying some LeetCode problems and I came across a "Check Duplicates" problem. When I do the tests tho, it doesn't work when the function receives the array [3,3]. I really can't understand why. Here is my code:
def containsDuplicate(nums) -> bool:
list = {}
for i in range (len(nums)):
if(3 in list):
return True
else:
list[i] = nums[i]
print(list[i])
return False
def main():
print(containsDuplicate([3,3]))
main()
Does anyone know why the "if" statement that's supposed to return True isn't working? PS I know I could use set or something like a hashmap but I just want to understand what I´m doing wrong in this case