[LeetCode]219 Contains Duplicate II
来源:互联网 发布:澳门银河网络平台 编辑:程序博客网 时间:2024/06/06 17:25
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.
Simple Java solution
public boolean containsNearbyDuplicate(int[] nums, int k) { Set<Integer> set = new HashSet<Integer>(); for(int i = 0; i < nums.length; i++){ if(i > k) set.remove(nums[i-k-1]); if(!set.add(nums[i])) return true; } return false; }
0 0
- leetcode 219: Contains Duplicate II
- LeetCode 219:Contains Duplicate II
- Contains Duplicate II - LeetCode 219
- Leetcode[219]-Contains Duplicate II
- LeetCode 219 Contains Duplicate II
- Leetcode 219 Contains Duplicate II
- 【Leetcode】Contains Duplicate II #219
- Leetcode 219 Contains Duplicate II
- leetcode 219:Contains Duplicate II
- LeetCode 219: Contains Duplicate II
- leetcode: (219) Contains Duplicate II
- leetcode 219: Contains Duplicate II
- [Leetcode]#219 Contains Duplicate II
- [LeetCode 219] Contains Duplicate II
- [leetcode 219] Contains Duplicate II
- 【LEETCODE】219-Contains Duplicate II
- 【LeetCode】219Contains Duplicate II
- LeetCode 219 Contains Duplicate II
- LeetCode 112. Path Sum
- 关于在不同版本和平台之间进行还原或复制的常见问题 (文档 ID 1526162.1)
- Linux Grub、Linux运行级别、终端模式登陆
- h5弹层之后阻止页面滚动
- 分布式框架学习
- [LeetCode]219 Contains Duplicate II
- UVa 11212 - Editing a Book
- Python爬虫包 BeautifulSoup 学习(九) 正则表达式与Lambda表达式
- android Fragment 中IllegalStateException异常问题
- Srvctl Does Not Work After the Grid infrastructure upgrade from 11gr2 to 12c (文档 ID 2132856.1)
- Tracing the LSNRCTL Control Utility (文档 ID 737530.1)
- rtmpdump的使用及遇到的问题
- Shell自删除脚本
- 用于深度学习 的Xilinx FPGA XC7K325T PCIeX8 处理板卡