leetcode-easy-array-217. Contains Duplicate
mycode 76.39%
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
if len(nums) == 0 or len(nums) == 1:
return False
return not (len(set(nums)) == len(nums))
参考
最快:
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
hasht = {}
for num in nums:
if num not in hasht:
hasht[num] = True
else:
return True
return False
leetcode-easy-array-217. Contains Duplicate的更多相关文章
- [LeetCode&Python] Problem 217. Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- [Array]217.Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return t ...
- 【leetcode❤python】217. Contains Duplicate
#-*- coding: UTF-8 -*- class Solution(object): def containsDuplicate(self, nums): numsdic= ...
- leetcode 217. Contains Duplicate 287. Find the Duplicate Number 442. Find All Duplicates in an Array 448. Find All Numbers Disappeared in an Array
后面3个题都是限制在1-n的,所有可以不先排序,可以利用巧方法做.最后两个题几乎一模一样. 217. Contains Duplicate class Solution { public: bool ...
- 217. Contains Duplicate【easy】
217. Contains Duplicate[easy] Given an array of integers, find if the array contains any duplicates. ...
- 25. leetcode 217. Contains Duplicate
217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...
- LN : leetcode 217 Contains Duplicate
lc 217 Contains Duplicate 217 Contains Duplicate Given an array of integers, find if the array conta ...
- LeetCode Javascript实现 169. Majority Element 217. Contains Duplicate(两个对象比较是否相等时,如果都指向同一个对象,a==b才是true)350. Intersection of Two Arrays II
169. Majority Element /** * @param {number[]} nums * @return {number} */ var majorityElement = funct ...
- 217. Contains Duplicate(C++)
217. Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your ...
- LeetCode(220) Contains Duplicate III
题目 Given an array of integers, find out whether there are two distinct indices i and j in the array ...
随机推荐
- 优雅的swiper实例
swiper实例 <!DOCTYPE html> <html lang="en"> <head> <meta name="vie ...
- vue单页应用首次加载太慢之性能优化
问题描述: 最近开发了一个单页应用,上线后发现页面初始加载要20s才能完成,这就很影响用户体验了,于是分析原因,发现页面加载时有个 vendor.js达到了3000多kb,于是在网上查找了一下原因,是 ...
- Ubuntu18.04 安装redis
Redis是常用基于内存的Key-Value数据库,比Memcache更先进,支持多种数据结构,高效,快速.用Redis可以很轻松解决高并发的数据访问问题:作为实时监控信号处理也非常不错. 安装red ...
- python中使用schedule模块定时执行任务
python中有一个轻量级的定时任务调度的库:schedule.他可以完成每分钟,每小时,每天,周几,特定日期的定时任务.因此十分方便我们执行一些轻量级的定时任务. 代码如下: import sche ...
- python snippets
1.Find memory used by an object import sys 2.Combine a list of strings into a single string strings ...
- Sublime Text2 常用快捷键总结
Ctrl+Tab 当前窗口中的标签页切换 Ctrl+Shift+D 复制光标所在整行,插入在该行之前 Ctrl+Shift+K 删除整行 Ctrl+Shift+/ 注释已选择内容 Ctrl+Shift ...
- [uboot] (第三章)uboot流程——uboot-spl代码流程(转)
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/ooonebook/article/det ...
- mysql慢查询分析
mysql慢查询分析 Posted: 29. 08. 2014 | Author: zdz | Category: mysql MySQL 慢查询日志分析 1. pt-query-digest分析慢查 ...
- thinkphp查询构造器和链式操作、事务
插入 更新记录 查询数据 删除数据 插入数据----name这种用法,会去config.php中去寻找前缀,如果你定义了前缀tp,那么执行下条语句会查询对tp_data的插入操作 链式操作---> ...
- java 流操作对文件的分割和合并的实例详解_java - JAVA
文章来源:嗨学网 敏而好学论坛www.piaodoo.com 欢迎大家相互学习 java 流操作对文件的分割和合并的实例详解 学习文件的输入输出流,自己做一个小的示例,对文件进行分割和合并. 下面是代 ...