1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/跳跃游戏 IV [jump-game-iv].html
2022-03-29 12:43:11 +08:00

50 lines
1.7 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给你一个整数数组&nbsp;<code>arr</code>&nbsp;,你一开始在数组的第一个元素处(下标为 0</p>
<p>每一步,你可以从下标&nbsp;<code>i</code>&nbsp;跳到下标&nbsp;<code>i + 1</code><code>i - 1</code> 或者 <code>j</code> </p>
<ul>
<li><code>i + 1</code> 需满足:<code>i + 1 &lt; arr.length</code></li>
<li><code>i - 1</code>&nbsp;需满足:<code>i - 1 &gt;= 0</code></li>
<li><code>j</code>&nbsp;需满足:<code>arr[i] == arr[j]</code>&nbsp;&nbsp;<code>i != j</code></li>
</ul>
<p>请你返回到达数组最后一个元素的下标处所需的&nbsp;<strong>最少操作次数</strong>&nbsp;</p>
<p>注意:任何时候你都不能跳到数组外面。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = [100,-23,-23,404,100,23,23,23,3,404]
<strong>输出:</strong>3
<strong>解释:</strong>那你需要跳跃 3 次,下标依次为 0 --&gt; 4 --&gt; 3 --&gt; 9 。下标 9 为数组的最后一个元素的下标。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = [7]
<strong>输出:</strong>0
<strong>解释:</strong>一开始就在最后一个元素处,所以你不需要跳跃。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>arr = [7,6,9,6,9,6,9,7]
<strong>输出:</strong>1
<strong>解释:</strong>你可以直接从下标 0 处跳到下标 7 处,也就是数组的最后一个元素处。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<meta charset="UTF-8" />
<ul>
<li><code>1 &lt;= arr.length &lt;= 5 * 10<sup>4</sup></code></li>
<li><code>-10<sup>8</sup>&nbsp;&lt;= arr[i] &lt;= 10<sup>8</sup></code></li>
</ul>