217. Contains Duplicate

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.

判断给定的数组是否含有重复值

思路:判断数组长度和数组取集合后的长度是否相同

解答:

class Solution(object):
    def containsDuplicate(self, nums):
        """
        :type nums: List[int]
        :rtype: bool
        """
        if nums == []:
            return False
        return False if len(nums)==len(set(nums)) else True
        
原文地址:https://www.cnblogs.com/sxbjdl/p/5418954.html