Package g0401_0500.s0464_can_i_win
Class Solution
java.lang.Object
g0401_0500.s0464_can_i_win.Solution
464 - Can I Win.<p>Medium</p>
<p>In the “100 game” two players take turns adding, to a running total, any integer from <code>1</code> to <code>10</code>. The player who first causes the running total to <strong>reach or exceed</strong> 100 wins.</p>
<p>What if we change the game so that players <strong>cannot</strong> re-use integers?</p>
<p>For example, two players might take turns drawing from a common pool of numbers from 1 to 15 without replacement until they reach a total >= 100.</p>
<p>Given two integers <code>maxChoosableInteger</code> and <code>desiredTotal</code>, return <code>true</code> if the first player to move can force a win, otherwise, return <code>false</code>. Assume both players play <strong>optimally</strong>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 11</p>
<p><strong>Output:</strong> false</p>
<p><strong>Explanation:</strong></p>
<p>No matter which integer the first player choose, the first player will lose.</p>
<p>The first player can choose an integer from 1 up to 10.</p>
<p>If the first player choose 1, the second player can only choose integers from 2 up to 10.</p>
<p>The second player will win by choosing 10 and get a total = 11, which is >= desiredTotal.</p>
<p>Same with other integers chosen by the first player, the second player will always win.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 0</p>
<p><strong>Output:</strong> true</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> maxChoosableInteger = 10, desiredTotal = 1</p>
<p><strong>Output:</strong> true</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= maxChoosableInteger <= 20</code></li>
<li><code>0 <= desiredTotal <= 300</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
canIWin
public boolean canIWin(int maxChoosableInteger, int desiredTotal)
-