Class Solution
java.lang.Object
g2601_2700.s2660_determine_the_winner_of_a_bowling_game.Solution
2660 - Determine the Winner of a Bowling Game.<p>Easy</p>
<p>You are given two <strong>0-indexed</strong> integer arrays <code>player1</code> and <code>player2</code>, that represent the number of pins that player 1 and player 2 hit in a bowling game, respectively.</p>
<p>The bowling game consists of <code>n</code> turns, and the number of pins in each turn is exactly <code>10</code>.</p>
<p>Assume a player hit <code>x<sub>i</sub></code> pins in the <code>i<sup>th</sup></code> turn. The value of the <code>i<sup>th</sup></code> turn for the player is:</p>
<ul>
<li><code>2x<sub>i</sub></code> if the player hit <code>10</code> pins in any of the previous two turns.</li>
<li>Otherwise, It is <code>x<sub>i</sub></code>.</li>
</ul>
<p>The score of the player is the sum of the values of their <code>n</code> turns.</p>
<p>Return</p>
<ul>
<li><code>1</code> <em>if the score of player 1 is more than the score of player 2,</em></li>
<li><code>2</code> <em>if the score of player 2 is more than the score of player 1, and</em></li>
<li><code>0</code> <em>in case of a draw.</em></li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> player1 = [4,10,7,9], player2 = [6,5,2,3]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> The score of player1 is 4 + 10 + 2<em>7 + 2</em>9 = 46.</p>
<p>The score of player2 is 6 + 5 + 2 + 3 = 16.</p>
<p>Score of player1 is more than the score of player2, so, player1 is the winner, and the answer is 1.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> player1 = [3,5,7,6], player2 = [8,10,10,2]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The score of player1 is 3 + 5 + 7 + 6 = 21.</p>
<p>The score of player2 is 8 + 10 + 2<em>10 + 2</em>2 = 42.</p>
<p>Score of player2 is more than the score of player1, so, player2 is the winner, and the answer is 2.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> player1 = [2,3], player2 = [4,1]</p>
<p><strong>Output:</strong> 0</p>
<p><strong>Explanation:</strong> The score of player1 is 2 + 3 = 5</p>
<p>The score of player2 is 4 + 1 = 5</p>
<p>The score of player1 equals to the score of player2, so, there is a draw, and the answer is 0.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>n == player1.length == player2.length</code></li>
<li><code>1 <= n <= 1000</code></li>
<li><code>0 <= player1[i], player2[i] <= 10</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
isWinner
public int isWinner(int[] player1, int[] player2)
-