1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-25 17:50:26 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/存在重复元素 III [contains-duplicate-iii].html

45 lines
1.5 KiB
HTML
Raw Normal View History

2023-12-09 18:42:21 +08:00
<p>给你一个整数数组 <code>nums</code> 和两个整数 <code>indexDiff</code><code>valueDiff</code></p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p>找出满足下述条件的下标对 <code>(i, j)</code></p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<ul>
<li><code>i != j</code>,</li>
<li><code>abs(i - j) &lt;= indexDiff</code></li>
<li><code>abs(nums[i] - nums[j]) &lt;= valueDiff</code></li>
</ul>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p>如果存在,返回 <code>true</code><em> </em>否则,返回<em> </em><code>false</code><em> </em></p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p>&nbsp;</p>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p><strong class="example">示例 1</strong></p>
2022-03-27 20:56:26 +08:00
<pre>
2023-12-09 18:42:21 +08:00
<strong>输入:</strong>nums = [1,2,3,1], indexDiff = 3, valueDiff = 0
<strong>输出:</strong>true
<strong>解释:</strong>可以找出 (i, j) = (0, 3) 。
满足下述 3 个条件:
i != j --&gt; 0 != 3
abs(i - j) &lt;= indexDiff --&gt; abs(0 - 3) &lt;= 3
abs(nums[i] - nums[j]) &lt;= valueDiff --&gt; abs(1 - 1) &lt;= 0
</pre>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p><strong class="example">示例 2</strong></p>
2022-03-27 20:56:26 +08:00
<pre>
2023-12-09 18:42:21 +08:00
<strong>输入:</strong>nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3
<strong>输出:</strong>false
<strong>解释:</strong>尝试所有可能的下标对 (i, j) ,均无法满足这 3 个条件,因此返回 false 。
</pre>
2022-03-27 20:56:26 +08:00
2023-12-09 18:42:21 +08:00
<p>&nbsp;</p>
2022-03-27 20:56:26 +08:00
<p><strong>提示:</strong></p>
<ul>
2023-12-09 18:42:21 +08:00
<li><code>2 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
<li><code>-10<sup>9</sup> &lt;= nums[i] &lt;= 10<sup>9</sup></code></li>
<li><code>1 &lt;= indexDiff &lt;= nums.length</code></li>
<li><code>0 &lt;= valueDiff &lt;= 10<sup>9</sup></code></li>
2022-03-27 20:56:26 +08:00
</ul>