mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
34 lines
1.1 KiB
HTML
34 lines
1.1 KiB
HTML
|
<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>k</code> ,判断数组中是否存在两个 <strong>不同的索引</strong><em> </em><code>i</code> 和<em> </em><code>j</code> ,满足 <code>nums[i] == nums[j]</code> 且 <code>abs(i - j) <= k</code> 。如果存在,返回 <code>true</code> ;否则,返回 <code>false</code> 。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>示例 1:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>nums = [1,2,3,1], k<em> </em>= 3
|
|||
|
<strong>输出:</strong>true</pre>
|
|||
|
|
|||
|
<p><strong>示例 2:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>nums = [1,0,1,1], k<em> </em>=<em> </em>1
|
|||
|
<strong>输出:</strong>true</pre>
|
|||
|
|
|||
|
<p><strong>示例 3:</strong></p>
|
|||
|
|
|||
|
<pre>
|
|||
|
<strong>输入:</strong>nums = [1,2,3,1,2,3], k<em> </em>=<em> </em>2
|
|||
|
<strong>输出:</strong>false</pre>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>1 <= nums.length <= 10<sup>5</sup></code></li>
|
|||
|
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
|||
|
<li><code>0 <= k <= 10<sup>5</sup></code></li>
|
|||
|
</ul>
|