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)/跳跃游戏 VI [jump-game-vi].html
2022-03-29 12:43:11 +08:00

42 lines
1.5 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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>给你一个下标从 <strong>0</strong> 开始的整数数组 <code>nums</code> 和一个整数 <code>k</code> 。</p>
<p>一开始你在下标 <code>0</code> 处。每一步,你最多可以往前跳 <code>k</code> 步,但你不能跳出数组的边界。也就是说,你可以从下标 <code>i</code> 跳到 <code>[i + 1 min(n - 1, i + k)]</code> <strong>包含</strong> 两个端点的任意位置。</p>
<p>你的目标是到达数组最后一个位置(下标为 <code>n - 1</code> ),你的 <strong>得分</strong> 为经过的所有数字之和。</p>
<p>请你返回你能得到的 <strong>最大得分</strong> 。</p>
<p> </p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>nums = [<strong>1</strong>,<strong>-1</strong>,-2,<strong>4</strong>,-7,<strong>3</strong>], k = 2
<b>输出:</b>7
<b>解释:</b>你可以选择子序列 [1,-1,4,3] (上面加粗的数字),和为 7 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [<strong>10</strong>,-5,-2,<strong>4</strong>,0,<strong>3</strong>], k = 3
<b>输出:</b>17
<b>解释:</b>你可以选择子序列 [10,4,3] (上面加粗数字),和为 17 。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<b>输入:</b>nums = [1,-5,-20,4,-1,3,-6,-3], k = 2
<b>输出:</b>0
</pre>
<p> </p>
<p><strong>提示:</strong></p>
<ul>
<li> <code>1 <= nums.length, k <= 10<sup>5</sup></code></li>
<li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li>
</ul>