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. 【转】C#自定义控件:WinForm将其它应用程序窗体嵌入自己内部

    PS:文末的附件已更新,这次我放到博客园里面了,不会弹出广告,放心下载,O(∩_∩)O谢谢! 这是最近在做的一个项目中提到的需求,把一个现有的窗体应用程序界面嵌入到自己开发的窗体中来,看起来就像自己开 ...

  2. CentOS6.3 下启动Oracle service和listener

    一.启动Oracle数据库和监听器 首先切换到Oracle专有用户: [root@NJZYY06 ~]# su - oracle [oracle@NJZYY06 ~]$ 1.启动数据库: [oracl ...

  3. BZOJ 3875: [Ahoi2014]骑士游戏

    d[i]表示消灭i所需的最小体力值, d[i] = min(S[i], K[i]+Σd[x]), Σd[x]表示普通攻击而产生的其他怪兽. 因为不是DAG, 所以用个队列类似SPFA来更新答案. -- ...

  4. mysql触发器使用注意

    1.在创建触发器的时候,语句中避免在一个select语句查询多个列,例如使用select a,b from table,应该分开使用select语句, 例如select a from table  s ...

  5. http://blog.csdn.net/zhanglvmeng/article/details/11928469

    本系列主要结合<PHP和MYSQL WEB开发 第四版>,在阅读中提出自己认为比较重要的一些问题,以加深对知识的了解程度. 1.简短.中等以及冗长风格的表单变量 $name; //简短风格 ...

  6. You have not agreed to the Xcode license.

    You have not agreed to the Xcode license. Before running the installer again please agree to the lic ...

  7. 【Howie玩docker】-docker安装

    windows忽略,小苹果木有,所以咱只看ubuntu和centOS的吧! 参考书<Docker技术入门与实战> Ubuntu 14.04安装Docker Ubuntu 14.04版本官方 ...

  8. Linux 内核无线子系统

    Linux 内核无线子系统 浅谈 Linux 内核无线子系统 Table of Contents 1. 全局概览 2. 模块间接口 3. 数据路径与管理路径 4. 数据包是如何被发送? 5. 谈谈管理 ...

  9. Microsoft Project 2010 简体中文专业版 + 永久激活密钥

    Microsoft Project 2010 简体中文专业版 + 永久激活密钥 (2014-02-17 11:44:16) 转载▼ 标签: 文化 分类: 学习 Microsoft Project已成为 ...

  10. android process bar 几种style

    process bar 圆形style记录 1. style="?android:attr/progressBarStyleSmall" //根据主题变颜色 2. holo 主题下 ...