mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
58 lines
2.3 KiB
HTML
58 lines
2.3 KiB
HTML
<p>Alice and Bob take turns playing a game, with Alice starting first.</p>
|
|
|
|
<p>There are <code>n</code> stones in a pile. On each player's turn, they can <strong>remove</strong> a stone from the pile and receive points based on the stone's value. Alice and Bob may <strong>value the stones differently</strong>.</p>
|
|
|
|
<p>You are given two integer arrays of length <code>n</code>, <code>aliceValues</code> and <code>bobValues</code>. Each <code>aliceValues[i]</code> and <code>bobValues[i]</code> represents how Alice and Bob, respectively, value the <code>i<sup>th</sup></code> stone.</p>
|
|
|
|
<p>The winner is the person with the most points after all the stones are chosen. If both players have the same amount of points, the game results in a draw. Both players will play <strong>optimally</strong>. Both players know the other's values.</p>
|
|
|
|
<p>Determine the result of the game, and:</p>
|
|
|
|
<ul>
|
|
<li>If Alice wins, return <code>1</code>.</li>
|
|
<li>If Bob wins, return <code>-1</code>.</li>
|
|
<li>If the game results in a draw, return <code>0</code>.</li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> aliceValues = [1,3], bobValues = [2,1]
|
|
<strong>Output:</strong> 1
|
|
<strong>Explanation:</strong>
|
|
If Alice takes stone 1 (0-indexed) first, Alice will receive 3 points.
|
|
Bob can only choose stone 0, and will only receive 2 points.
|
|
Alice wins.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> aliceValues = [1,2], bobValues = [3,1]
|
|
<strong>Output:</strong> 0
|
|
<strong>Explanation:</strong>
|
|
If Alice takes stone 0, and Bob takes stone 1, they will both have 1 point.
|
|
Draw.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> aliceValues = [2,4,3], bobValues = [1,6,7]
|
|
<strong>Output:</strong> -1
|
|
<strong>Explanation:</strong>
|
|
Regardless of how Alice plays, Bob will be able to have more points than Alice.
|
|
For example, if Alice takes stone 1, Bob can take stone 2, and Alice takes stone 0, Alice will have 6 points to Bob's 7.
|
|
Bob wins.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>n == aliceValues.length == bobValues.length</code></li>
|
|
<li><code>1 <= n <= 10<sup>5</sup></code></li>
|
|
<li><code>1 <= aliceValues[i], bobValues[i] <= 100</code></li>
|
|
</ul>
|