<LeetCode><Easy> 219 ContainDuplicate 2
来源:互联网 发布:可乐冰cV淘宝店 编辑:程序博客网 时间:2024/06/06 07:09
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.
#Python2 72ms
class Solution(object): def containsNearbyDuplicate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: bool """ nDict={} for e2,n in enumerate(nums): try: e1=nDict[n] if e2-e1<=k:return True else:nDict[n]=e2 except: nDict[n]=e2 return False
1 0
- <LeetCode><Easy> 219 ContainDuplicate 2
- Leetcode--easy系列2
- leetcode easy
- LeetCode--easy
- [Leetcode 219, Easy] Contains Duplicate II
- 【LeetCode】2(7)Remove Element(Easy)
- LeetCode系列Easy【2】 Algorithms - Array
- LeetCode-Easy刷题(2) Reverse Integer
- Leetcode[Easy] - Valid Palindrome
- Leetcode[Easy] - Path Sum
- Leetcode[Easy] - Two Sum
- Leetcode[easy] - Implement strStr()
- Leetcode--easy系列1
- Leetcode--easy系列3
- Leetcode--easy系列4
- Leetcode--easy系列5
- Leetcode--easy系列6
- Leetcode--easy系列7
- Pthread创建线程后必须使用join或detach释放线程资源
- 线性表--单链表
- 浅谈HTTP的无状态性和Cookie、Session来源
- 跟我学SpringMVC目录汇总贴、PDF下载、源码下载
- C:\windows\softwaredistribution 文件过大如何处理
- <LeetCode><Easy> 219 ContainDuplicate 2
- 阿里2015实习生招聘在线测试----编程题,设计有限任务响应队列
- android studio -- 图片应该放在drawable还是mipmap?
- x86-64和IA32的主要区别
- #pragma详解
- ajaxFileUpload 异步上传文件
- Building Apps Faster with Android Data Binding
- pthread_attr_init线程属性
- 代码工具1. 自动根据json字符串生成javabean类