217. Contains Duplicate

来源:互联网 发布:mac pro 充电器价格 编辑:程序博客网 时间:2024/05/16 06:00

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.

Answer with python:

class Solution(object):    def containsDuplicate(self, nums):        """        :type nums: List[int]        :rtype: bool        """        if len(nums)==0:            return False        numbers=set()             '''定义一个空集合'''        numbers.update(nums)      '''添加数组进集合'''                 if len(numbers)==len(nums):            return False        else:            return True
0 0
原创粉丝点击