mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
72 lines
2.5 KiB
HTML
72 lines
2.5 KiB
HTML
|
<p>在神秘的地牢中,<code>n</code> 个魔法师站成一排。每个魔法师都拥有一个属性,这个属性可以给你提供能量。有些魔法师可能会给你负能量,即从你身上吸取能量。</p>
|
|||
|
|
|||
|
<p>你被施加了一种诅咒,当你从魔法师 <code>i</code> 处吸收能量后,你将被立即传送到魔法师 <code>(i + k)</code> 处。这一过程将重复进行,直到你到达一个不存在 <code>(i + k)</code> 的魔法师为止。</p>
|
|||
|
|
|||
|
<p>换句话说,你将选择一个起点,然后以 <code>k</code> 为间隔跳跃,直到到达魔法师序列的末端,<strong>在过程中吸收所有的能量</strong>。</p>
|
|||
|
|
|||
|
<p>给定一个数组 <code>energy</code> 和一个整数<code>k</code>,返回你能获得的<strong> 最大 </strong>能量。</p>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong class="example">示例 1:</strong></p>
|
|||
|
|
|||
|
<div class="example-block" style="
|
|||
|
border-color: var(--border-tertiary);
|
|||
|
border-left-width: 2px;
|
|||
|
color: var(--text-secondary);
|
|||
|
font-size: .875rem;
|
|||
|
margin-bottom: 1rem;
|
|||
|
margin-top: 1rem;
|
|||
|
overflow: visible;
|
|||
|
padding-left: 1rem;
|
|||
|
">
|
|||
|
<p><strong>输入:</strong><span class="example-io" style="
|
|||
|
font-family: Menlo,sans-serif;
|
|||
|
font-size: 0.85rem;
|
|||
|
"> energy = [5,2,-10,-5,1], k = 3</span></p>
|
|||
|
|
|||
|
<p><strong>输出:</strong><span class="example-io" style="
|
|||
|
font-family: Menlo,sans-serif;
|
|||
|
font-size: 0.85rem;
|
|||
|
"> 3</span></p>
|
|||
|
|
|||
|
<p><strong>解释:</strong>可以从魔法师 1 开始,吸收能量 2 + 1 = 3。</p>
|
|||
|
</div>
|
|||
|
|
|||
|
<p><strong class="example">示例 2:</strong></p>
|
|||
|
|
|||
|
<div class="example-block" style="
|
|||
|
border-color: var(--border-tertiary);
|
|||
|
border-left-width: 2px;
|
|||
|
color: var(--text-secondary);
|
|||
|
font-size: .875rem;
|
|||
|
margin-bottom: 1rem;
|
|||
|
margin-top: 1rem;
|
|||
|
overflow: visible;
|
|||
|
padding-left: 1rem;
|
|||
|
">
|
|||
|
<p><strong>输入:</strong><span class="example-io" style="
|
|||
|
font-family: Menlo,sans-serif;
|
|||
|
font-size: 0.85rem;
|
|||
|
"> energy = [-2,-3,-1], k = 2</span></p>
|
|||
|
|
|||
|
<p><strong>输出:</strong><span class="example-io" style="
|
|||
|
font-family: Menlo,sans-serif;
|
|||
|
font-size: 0.85rem;
|
|||
|
"> -1</span></p>
|
|||
|
|
|||
|
<p><strong>解释:</strong>可以从魔法师 2 开始,吸收能量 -1。</p>
|
|||
|
</div>
|
|||
|
|
|||
|
<p> </p>
|
|||
|
|
|||
|
<p><strong>提示:</strong></p>
|
|||
|
|
|||
|
<ul>
|
|||
|
<li><code>1 <= energy.length <= 10<sup>5</sup></code></li>
|
|||
|
<li><code>-1000 <= energy[i] <= 1000</code></li>
|
|||
|
<li><code>1 <= k <= energy.length - 1</code></li>
|
|||
|
</ul>
|
|||
|
|
|||
|
<p> </p>
|