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 j is at most k.

class Solution:
# @param {integer[]} nums
# @param {integer} k
# @return {boolean}
def containsNearbyDuplicate(self, nums, k):
length = len( nums )
if length <= 1:
return False
if k <= 0:
return False
arrMap = {}
for i in range(0, length):
if arrMap.has_key( nums[i] ):
j = arrMap[nums[i]]
if i - j <= k:
return True
arrMap[nums[i]] = i
return False

leetcode Contains Duplicate II python的更多相关文章

  1. [leetcode]Word Ladder II @ Python

    [leetcode]Word Ladder II @ Python 原题地址:http://oj.leetcode.com/problems/word-ladder-ii/ 参考文献:http://b ...

  2. [leetcode] Contains Duplicate II

    Contains Duplicate II Given an array of integers and an integer k, find out whether there there are ...

  3. [LeetCode] Contains Duplicate(II,III)

    Contains Duplicate Given an array of integers, find if the array contains any duplicates. Your funct ...

  4. [LeetCode] Contains Duplicate II 包含重复值之二

    Given an array of integers and an integer k, return true if and only if there are two distinct indic ...

  5. leetcode Combination Sum II python

    Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...

  6. [leetcode]Unique Paths II @ Python

    原题地址:https://oj.leetcode.com/problems/unique-paths-ii/ 题意: Follow up for "Unique Paths": N ...

  7. [leetcode]Spiral Matrix II @ Python

    原题地址:https://oj.leetcode.com/problems/spiral-matrix-ii/ 题意: Given an integer n, generate a square ma ...

  8. [leetcode]Word Break II @ Python

    原题地址:https://oj.leetcode.com/problems/word-break-ii/ 题意: Given a string s and a dictionary of words  ...

  9. [leetcode]Palindrome Partitioning II @ Python

    原题地址:https://oj.leetcode.com/problems/palindrome-partitioning-ii/ 题意: Given a string s, partition s  ...

随机推荐

  1. [mysqldumpslow 报错] Died at /usr/local/mysql/bin/mysqldumpslow line 161, &lt;&gt; chunk 236.

    mysqldumpslow报错:Died at /usr/local/mysql/bin/mysqldumpslow line 161, <> chunk 236. 总结:是由于top数目 ...

  2. [置顶] hdu2815 扩展Baby step,Giant step入门

    题意:求满足a^x=b(mod n)的最小的整数x. 分析:很多地方写到n是素数的时候可以用Baby step,Giant step, 其实研究过Baby step,Giant step算法以后,你会 ...

  3. gdb调试python

    一.概述 有时我们会想调试一个正在运行的Python进程,或者一个Python进程的coredump.例如现在遇到一个mod_wsgi的进程僵死了,不接受请求,想看看究竟是运行到哪行Python代码呢 ...

  4. javascript高级知识点——内置对象原型

    代码信息来自于http://ejohn.org/apps/learn/. 可以修改内置对象的方法. if (!Array.prototype.forEach) { Array.prototype.fo ...

  5. sqlserver查询某一字段重复超5次的所有记录

    用的sqlserver2008 r2. SELECT  * FROM t_class WHERE id IN (SELECT  id FROM (SELECT  ROW_NUMBER() OVER ( ...

  6. iOS进阶:Objective-C runtime(一)

    第一次看到runtime时,觉得太高大上,动态获取方法.属性等简直厉害的不要不要的.在经过查找资料+实践后,发现runtime并没有想象中那么复杂,接下来对runtime进行基本的介绍. 要使用运行时 ...

  7. Oracle视图,序列及同义词、集合操作

    一.视图(重点) 视同的功能:一个视图其实就是封装了一个复杂的查询语句.1.创建视图的语法:CREATE VIEW 视图名称 AS 子查询 范例:创建一个包含了20部门的视图CREATE VIEW e ...

  8. MFC CListCtrl得到ctrl,shift多选的行号

    vector<int> selVect; int count = m_consumeList.GetItemCount(); //你的列表多少行 for (int i = 0; i< ...

  9. 关于ODI agent的配置部署

    分类: Linux 最近,做了几个ODI项目的部署,发现ODI agent所在的位置对整个E-LT工作的影响还是比较大的,根据Oracle的官方说法,agent一般需要部署在目标端的数据库服务器上,或 ...

  10. Oracle EBS-SQL (SYS-12):查询各Profile的设置情况.sql

    SELECT pro.profile_option_name, pro.user_profile_option_name, lev.level_type TYPE, --lev.level_code, ...