您的位置:首页 > 大数据 > 人工智能

(LeetCode)Contains Duplicate -- 查看数组是否重复

2016-07-26 09:34 381 查看
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.

Subscribe to see which companies asked this question

解题分析:
题目过于简单,判断数组中是否有重复的。

# -*- coding:utf-8 -*-
__author__ = 'jiuzhang'
class Solution(object):
def containsDuplicate(self, nums):
return len(nums) != len(set(nums))

'''
测试部分
nums = [2,2, 3, 4, 5, 6]
S = Solution()
a = S.containsDuplicate(nums)
print a
'''
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: