AI智能
改变未来

LeetCode 219. Contains Duplicate II

[code]class Solution {public boolean containsNearbyDuplicate(int[] nums, int k) {// Corner Caseif(nums == null || nums.length == 0){return false;}Map<Integer, Integer> seen = new HashMap<>();for(int i = 0; i < nums.length; i++){if(seen.containsKey(nums[i])){if(i - seen.get(nums[i]) <= k){return true;}}// Add or update the valueseen.put(nums[i], i);}return false;}}

 

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » LeetCode 219. Contains Duplicate II