1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-12 02:41:42 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/problem (Chinese)/移动石子直到连续 II [moving-stones-until-consecutive-ii].html
2025-01-09 20:29:41 +08:00

52 lines
2.0 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>在 X 轴上有一些不同位置的石子。给定一个整数数组&nbsp;<code>stones</code>&nbsp;表示石子的位置。</p>
<p>如果一个石子在最小或最大的位置,称其为&nbsp;<strong>端点石子</strong>。每个回合,你可以将一颗 <strong>端点石子</strong> 拿起并移动到一个未占用的位置,使得该石子不再是一颗 <strong>端点石子</strong></p>
<ul>
<li>值得注意的是,如果石子像&nbsp;<code>stones = [1,2,5]</code>&nbsp;这样,你将 <strong>无法 </strong>移动位于位置 <code>5</code> 的端点石子,因为无论将它移动到任何位置(例如 <code>0</code><code>3</code>),该石子都仍然会是端点石子。</li>
</ul>
<p>当你无法进行任何移动时,即,这些石子的位置连续时,游戏结束。</p>
<p>以长度为 2 的数组形式返回答案,其中:</p>
<ul>
<li><code>answer[0]</code>&nbsp;是你可以移动的最小次数</li>
<li><code>answer[1]</code>&nbsp;是你可以移动的最大次数。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>[7,4,9]
<strong>输出:</strong>[1,2]
<strong>解释:</strong>
我们可以移动一次4 -&gt; 8游戏结束。
或者,我们可以移动两次 9 -&gt; 54 -&gt; 6游戏结束。
</pre>
<p><strong>示例&nbsp;2</strong></p>
<pre>
<strong>输入:</strong>[6,5,4,3,10]
<strong>输出:</strong>[2,3]
<strong>解释:</strong>
我们可以移动 3 -&gt; 8接着是 10 -&gt; 7游戏结束。
或者,我们可以移动 3 -&gt; 7, 4 -&gt; 8, 5 -&gt; 9游戏结束。
注意,我们无法进行 10 -&gt; 2 这样的移动来结束游戏,因为这是不合要求的移动。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>3 &lt;= stones.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= stones[i] &lt;= 10<sup>9</sup></code></li>
<li><code>stones</code>&nbsp;的值各不相同。</li>
</ul>
<p>&nbsp;</p>