Skip to content

Latest commit

 

History

History
67 lines (45 loc) · 1.24 KB

[0219] 存在重复元素 II.md

File metadata and controls

67 lines (45 loc) · 1.24 KB
title tags categories author comments updated permalink mathjax top description date
[0219] 存在重复元素 II
leetcode
leetcode
张学志
true
false
false
false
...
2019-12-31 16:03:39 -0800

题目描述

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

示例 1:

输入: nums = [1,2,3,1], k = 3
输出: true

示例 2:

输入: nums = [1,0,1,1], k = 1
输出: true

示例 3:

输入: nums = [1,2,3,1,2,3], k = 2
输出: false
Related Topics
  • 数组
  • 哈希表
  • 题目代码

    class Solution {
    public:
        bool containsNearbyDuplicate(vector<int>& nums, int k) {
    
        }
    };

    题目解析

    方法一

    方法二

    方法三