Given an array of integers, find if the array contains any duplicates.

Your function should return true if any value appears at least twice in the array, and it should return false if every element is distinct.

Example 1:


Input: [1,2,3,1]
Output: true

Example 2:


Input: [1,2,3,4]
Output: false

Example 3:


Input: [1,1,1,3,3,4,3,2,4,2]
Output: true

Difficulty: introductory

Starter code:

class Solution:
    def containsDuplicate(self, nums: List[int]) -> bool:
        

Solutions:
class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         num_set = set(nums)
         if len(nums) == len(num_set):
             return False
         return True


class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         """
         set_nums = set(nums)
         if len(set_nums) < len(nums):
             return True
         return False
         """
         dict1 = {}
         for num in nums:
             dict1[num] = dict1.get(num,0)+1
         
         for key in dict1:
             if dict1[key] > 1:
                 return True
         return False


class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         nums.sort()
         
         if len(nums)-1 == 1:
             if nums[0] == nums[1]:
                 return True
         
         for i in range(1,len(nums)):
             print(i)
          
             if nums[i] == nums[i-1]:
                 return True
 
             
         return False

class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         myDict = collections.Counter(nums)
         print(myDict)
         for value in list(myDict.values()):
             if value>1:
                 return True
         else:
             return False
                 


class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         nums.sort()
         
         for i in range(1,len(nums)):
             print(i)
          
             if nums[i] == nums[i-1]:
                 return True
 
             
         return False

class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         # dic = {}
         # for i in range(len(nums)):
         #     if nums[i] in dic.keys():
         #         return True
         #     dic[nums[i]] = i
         # return False
         nums.sort()
         for i in range(len(nums) - 1):
             if nums[i] == nums[i+1]:
                 return True
         return False

class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         
         diction = {}
         flag = 0
         for number in nums:
             if number not in diction:
                 diction[number] = 1
             else:
                 flag = 1
                 break
         if flag == 1:
             return True
         else:
             return False


class Solution:
     def containsDuplicate(self, nums):
         
         if len(nums) < 2:
             return False
         return True if len(set(nums)) < len(nums) else False
         
         """
         :type nums: List[int]
         :rtype: bool
         """


class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         if nums == None or len(nums) <= 1:
             return False
         map = {}
         for i in nums:
             if i in map:
                 return True
             else:
                 map[i] = 0
 
         return False

class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         myDict = {}
         for num in nums:
             if myDict.get(num):
                 return True
             else:
                 myDict[num] = 1
         else:
             return False
                 


class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         n_map = {}
         for n in nums:
             if n in n_map:
                 n_map[n] += 1
             else:
                 n_map[n] = 1
         for n, count in n_map.items():
             if count != 1:
                 return True
         return False

class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         hashmap = {}
         for i in nums:
             if i in hashmap.keys():
                 return True
             else:
                 hashmap[i] = hash(i)
         return False

class Solution:
     def containsDuplicate(self,nums):
         if(len(nums)>1):
             count=0
             giru=[]
             nums.sort()
             for i in range(len(nums)):
                 if i+1<len(nums):
                     if(nums[i]==nums[i+1]):
                         count=count+1
 
             if(count>0):
                 return True
             else: return False
         else :
             return False
             """
         :type nums: List[int]
         :rtype: bool
         """


class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         d = {}
         for num in nums:
             if num in d:
                 return True
             else:
                 d[num] = 1
         return False
         


class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         xx = dict()
         for i in range(len(nums)):
             if nums[i] in xx:
                 return True
             else:
                 xx[nums[i]] = 1
         return False

class Solution:
     def containsDuplicate(self, nums):
         """
         :type nums: List[int]
         :rtype: bool
         """
         seen = dict()
         for num in nums:
             if str(num) in seen:
                 return True
             else:
                 seen[str(num)] = 1
         return False