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