1.编辑器

我使用的是win10+vscode+leetcode+python3
环境配置参见我的博客:
链接

2.第二百一十九题

(1)题目
英文:

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 absolute difference between i and j is at most k.

中文:
给定一个整数数组和一个整数 k,判断数组中是否存在两个不同的索引 i 和 j,使得 nums [i] = nums [j],并且 i 和 j 的差的 绝对值 至多为 k。

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/contains-duplicate-ii

(2)解法
使用哈希表
(耗时:64ms,内存:21.4M)

class Solution:def containsNearbyDuplicate(self, nums: List[int], k: int) -> bool:arr={}for i in range(len(nums)):if nums[i] in arr and i-arr[nums[i]]<=k:return Truearr[nums[i]]=ireturn False

leetcode python3 简单题219. Contains Duplicate II相关推荐

  1. leetcode python3 简单题217. Contains Duplicate

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百一十七题 (1)题目 英文: Given an array of intege ...

  2. leetcode python3 简单题167. Two Sum II - Input array is sorted

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百六十七题 (1)题目 英文: Given an array of intege ...

  3. leetcode python3 简单题122. Best Time to Buy and Sell Stock II

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百二十二题 (1)题目 英文: Say you have an array pr ...

  4. leetcode python3 简单题119. Pascal's Triangle II

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十九题 (1)题目 英文: Given a non-negative ind ...

  5. leetcode python3 简单题225. Implement Stack using Queues

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十五题 (1)题目 英文: Implement the following ...

  6. leetcode python3 简单题70. Climbing Stairs

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: You are climbing a stair ca ...

  7. leetcode python3 简单题69. Sqrt(x)

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第六十九题 (1)题目 英文: Implement int sqrt(int x). ...

  8. leetcode python3 简单题53. Maximum Subarray

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十三题 (1)题目 英文: Given an integer array num ...

  9. leetcode python3 简单题58. Length of Last Word

    1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十八题 (1)题目 英文: Given a string s consists ...

最新文章

  1. 26.使用ajaxSetup()方法设置全局Ajax默认选项
  2. 好文 | 架构师更多的是和人打交道,说说我见到和听说到的架构师升级步骤和平时的工作内容
  3. Python语言学习:解决python版本升级问题集合(python2系列→Python3系列)导致错误的总结集合
  4. 1066 Root of AVL Tree (25 分)【难 / 知识点: 平衡树 未完成】
  5. 数据库元数据数据字典查询_6_列出给定表的外键引用
  6. 红橙Darren视频笔记 bsdiff bspatch 使用(Linux下)
  7. 在Java中获取系统属性
  8. out.print 嵌套html代码_代码规范之前端编写码规范
  9. java类库详解_【Java系列-4】Java常用类库_详解
  10. MobData活动预告 | 数据智能助力文创产业发展
  11. 记一次Comparator.comparing(XXX::getStartTime).reversed()失效
  12. 惠普战66键盘win10亮度调节快捷键失灵的解决办法
  13. MOS管当开关控制时,一般用PMOS做上管NMOS做下管的原因
  14. 一台电脑寿命一般几年?
  15. 阿里达摩院最新FEDformer,长程时序预测全面超越SOTA | ICML 2022
  16. 计算机大作业说明文档,计算机大作业.doc
  17. 复旦大学李孝男博士:结合词典的中文命名实体识别
  18. 一部值得收藏的PDA进化史
  19. 美国的网络空间安全国家战略
  20. 计算机辅助三维诊断英文,人体CT图像的三维可视化(英文)

热门文章

  1. 望城2019年华为软件云项目_今天,华为、京东两大项目在长沙开工
  2. python大作业数独_python做一个数独小游戏
  3. C++中如何小数点后精确到两位输出
  4. AcWing 101. 最高的牛
  5. 矩阵快速幂(附模板)
  6. Java 1.2.1 读取输入
  7. 数学式子中arg min,arg max的含义
  8. 目标检测——使用loss发现噪声数据
  9. R every day !
  10. 使用 docker 命令不用加 sudo