题目:

'''
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
''' '''
给定一个整数数组,找到该数组是否包含任何重复。 如果任何值在数组中至少出现两次,则函数应返回true,如果每个元素都不同,则函数应返回false。
'''

解法一55ms:

class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
if len(nums) == 0:
return False
else:
arr = {}
for i in range(len(nums)):
if nums[i] in arr:
return True
else:
arr[nums[i]] = i
else:
return False

解法二48ms:(一行)

class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
return len(nums) != len(set(nums))

LeetCode【第217题】Contains Duplicate的更多相关文章

  1. 【LeetCode】217 & 219 - Contains Duplicate & Contains Duplicate II

     217 - Contains Duplicate Given an array of integers, find if the array contains any duplicates. You ...

  2. leetcode第217.题存在重复元素

    1.题目描述 给定一个整数数组,判断是否存在重复元素. 如果任何值在数组中出现至少两次,函数返回 true.如果数组中每个元素都不相同,则返回 false. 2.示例 2.1 输入: [1,2,3,1 ...

  3. LeetCode(217)Contains Duplicate

    题目 Given an array of integers, find if the array contains any duplicates. Your function should retur ...

  4. Leetcode算法刷题:217和219题 Contains Duplicate

    从题目名字就可以看出这两道题是相似的,219是217的加强版 217:Contains Duplicate 题目 给予一个数组,判断是否有重复的元素.如果有就返回True,没有就返回False.以下是 ...

  5. LeetCode第[18]题(Java):4Sum 标签:Array

    题目难度:Medium 题目: Given an array S of n integers, are there elements a, b, c, and d in S such that a + ...

  6. Leetcode第 217 场周赛(思维量比较大)

    Leetcode第 217 场周赛 比赛链接:点这里 做完前两题我就知道今天的竞赛我已经结束了 这场比赛思维量还是比较大的. 1673. 找出最具竞争力的子序列 题目 给你一个整数数组 nums 和一 ...

  7. leetcode 第188题,我的解法,Best Time to Buy and Sell Stock IV

    <span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255) ...

  8. leetcode第37题--Count and Say

    题目:(据说是facebook的面试题哦) The count-and-say sequence is the sequence of integers beginning as follows:1, ...

  9. LeetCode第[1]题(Java):Two Sum 标签:Array

    题目: Given an array of integers, return indices of the two numbers such that they add up to a specifi ...

  10. LeetCode的刷题利器(伪装到老板都无法diss你没有工作)

    在工程效率大行其道的今天,如果不会写点代码以后也不容易在测试圈混下去.今天给大家推荐一个LeetCode的刷题利器,可以伪装到连你老板在这里走过去都无法确认你是在干活呢,还是在干活呢. LeetCod ...

随机推荐

  1. 跟我学SpringMVC目录汇总贴、PDF下载、源码下载

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  2. vector中的resize与 reserve

    void reserve (size_type n); reserver函数用来给vector预分配存储区大小,即capacity的值 ,但是没有给这段内存进行初始化.reserve 的参数n是推荐预 ...

  3. 给未来的你——李开复2011级大学新生演讲

    2011年09月26日08:30 来源:<中国青年报> <中国青年报>的读者朋友们: 你们肩负着中华的未来,你们身上正涌动着创新的血脉! 无论你在哪所学校,哪个城市,你都是与众 ...

  4. [转]VS2010 (C#)winform程序打包发布图解

    1.新建一个Windows窗体应用程序,例如项目名为monitor,功能略.新建的时候不要忘了创建解决方案. 2.在monitor解决方案上“右击”—— “添加”——“新建项目”,选择“其他类型项目” ...

  5. 神奇的 BlocksKit(1):源码分析(上)

    高能预警:本篇文章非常长,因为 BlocksKit 的实现还是比较复杂和有意的.这篇文章不是为了剖析 iOS 开发中的 block 的实现以及它是如何组成甚至使用的,如果你想通过这篇文章来了解 blo ...

  6. Android 自定义View修炼-Android 实现自定义的卫星式菜单(弧形菜单)View

    一.总述 Android 实现卫星式菜单也叫弧形菜单的主要要做的工作如下:1.动画的处理2.自定义ViewGroup来实现卫星式菜单View (1)自定义属性       a. 在attrs.xml中 ...

  7. Java public, private, protected and default

    Class       Package       Subclass    World public               y             y                 y   ...

  8. Storm集群扩容——从单机模式拓展到集群模式,以此类推

    Storm是分布式的实时流处理系统,单机模式肯本不能体现其强大特点,尤其是当需要处理的数据很大很快的 时候,Storm可以随时扩容,而且操作非常简单,编写的应用程序自动负载均衡. 前面已经介绍了如何安 ...

  9. bash调试执行

    bash -x 调试执行 bash -n 测试语法

  10. SVN修改已提交版本的日志

    在工作中一直是使用svn进行项目的版本控制的,有时候由于提交匆忙,或是忘了添加Log,或是Log内容写的有错误.今日遇到此类情况,想要在查看项目的日志时添加log或是修改log内容,遇到如下错误:Re ...