leetcode python3 简单题219. Contains Duplicate II
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相关推荐
- leetcode python3 简单题217. Contains Duplicate
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百一十七题 (1)题目 英文: Given an array of intege ...
- leetcode python3 简单题167. Two Sum II - Input array is sorted
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百六十七题 (1)题目 英文: Given an array of intege ...
- leetcode python3 简单题122. Best Time to Buy and Sell Stock II
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百二十二题 (1)题目 英文: Say you have an array pr ...
- leetcode python3 简单题119. Pascal's Triangle II
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第一百一十九题 (1)题目 英文: Given a non-negative ind ...
- leetcode python3 简单题225. Implement Stack using Queues
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第二百二十五题 (1)题目 英文: Implement the following ...
- leetcode python3 简单题70. Climbing Stairs
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第七十题 (1)题目 英文: You are climbing a stair ca ...
- leetcode python3 简单题69. Sqrt(x)
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第六十九题 (1)题目 英文: Implement int sqrt(int x). ...
- leetcode python3 简单题53. Maximum Subarray
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十三题 (1)题目 英文: Given an integer array num ...
- leetcode python3 简单题58. Length of Last Word
1.编辑器 我使用的是win10+vscode+leetcode+python3 环境配置参见我的博客: 链接 2.第五十八题 (1)题目 英文: Given a string s consists ...
最新文章
- 26.使用ajaxSetup()方法设置全局Ajax默认选项
- 好文 | 架构师更多的是和人打交道,说说我见到和听说到的架构师升级步骤和平时的工作内容
- Python语言学习:解决python版本升级问题集合(python2系列→Python3系列)导致错误的总结集合
- 1066 Root of AVL Tree (25 分)【难 / 知识点: 平衡树 未完成】
- 数据库元数据数据字典查询_6_列出给定表的外键引用
- 红橙Darren视频笔记 bsdiff bspatch 使用(Linux下)
- 在Java中获取系统属性
- out.print 嵌套html代码_代码规范之前端编写码规范
- java类库详解_【Java系列-4】Java常用类库_详解
- MobData活动预告 | 数据智能助力文创产业发展
- 记一次Comparator.comparing(XXX::getStartTime).reversed()失效
- 惠普战66键盘win10亮度调节快捷键失灵的解决办法
- MOS管当开关控制时,一般用PMOS做上管NMOS做下管的原因
- 一台电脑寿命一般几年?
- 阿里达摩院最新FEDformer,长程时序预测全面超越SOTA | ICML 2022
- 计算机大作业说明文档,计算机大作业.doc
- 复旦大学李孝男博士:结合词典的中文命名实体识别
- 一部值得收藏的PDA进化史
- 美国的网络空间安全国家战略
- 计算机辅助三维诊断英文,人体CT图像的三维可视化(英文)