mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-12 10:51:42 +08:00
存量题库数据更新
This commit is contained in:
@@ -1,22 +1,42 @@
|
||||
<p>Given an integer array <code>nums</code> and two integers <code>k</code> and <code>t</code>, return <code>true</code> if there are <strong>two distinct indices</strong> <code>i</code> and <code>j</code> in the array such that <code>abs(nums[i] - nums[j]) <= t</code> and <code>abs(i - j) <= k</code>.</p>
|
||||
<p>You are given an integer array <code>nums</code> and two integers <code>indexDiff</code> and <code>valueDiff</code>.</p>
|
||||
|
||||
<p>Find a pair of indices <code>(i, j)</code> such that:</p>
|
||||
|
||||
<ul>
|
||||
<li><code>i != j</code>,</li>
|
||||
<li><code>abs(i - j) <= indexDiff</code>.</li>
|
||||
<li><code>abs(nums[i] - nums[j]) <= valueDiff</code>, and</li>
|
||||
</ul>
|
||||
|
||||
<p>Return <code>true</code><em> if such pair exists or </em><code>false</code><em> otherwise</em>.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Example 1:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = [1,2,3,1], k = 3, t = 0
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,2,3,1], indexDiff = 3, valueDiff = 0
|
||||
<strong>Output:</strong> true
|
||||
</pre><p><strong>Example 2:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = [1,0,1,1], k = 1, t = 2
|
||||
<strong>Output:</strong> true
|
||||
</pre><p><strong>Example 3:</strong></p>
|
||||
<pre><strong>Input:</strong> nums = [1,5,9,1,5,9], k = 2, t = 3
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> We can choose (i, j) = (0, 3).
|
||||
We satisfy the three conditions:
|
||||
i != j --> 0 != 3
|
||||
abs(i - j) <= indexDiff --> abs(0 - 3) <= 3
|
||||
abs(nums[i] - nums[j]) <= valueDiff --> abs(1 - 1) <= 0
|
||||
</pre>
|
||||
|
||||
<p><strong class="example">Example 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong> nums = [1,5,9,1,5,9], indexDiff = 2, valueDiff = 3
|
||||
<strong>Output:</strong> false
|
||||
<strong>Explanation:</strong> After trying all the possible pairs (i, j), we cannot satisfy the three conditions, so we return false.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
<p><strong>Constraints:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>1 <= nums.length <= 2 * 10<sup>4</sup></code></li>
|
||||
<li><code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code></li>
|
||||
<li><code>0 <= k <= 10<sup>4</sup></code></li>
|
||||
<li><code>0 <= t <= 2<sup>31</sup> - 1</code></li>
|
||||
<li><code>2 <= nums.length <= 10<sup>5</sup></code></li>
|
||||
<li><code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code></li>
|
||||
<li><code>1 <= indexDiff <= nums.length</code></li>
|
||||
<li><code>0 <= valueDiff <= 10<sup>9</sup></code></li>
|
||||
</ul>
|
||||
|
Reference in New Issue
Block a user