2660. Determine the Winner of a Bowling Game

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public int isWinner(int[] player1, int[] player2) {
int player1Score = getTotalScore(player1);
int player2Score = getTotalScore(player2);

return player1Score == player2Score ? 0 : player1Score > player2Score ? 1 : 2;
}

private int getTotalScore(int[] player) {
int score = player[0];

for (int i = 1; i < player.length; i++) {
if (player[i - 1] == 10 || (i - 2 >= 0 && player[i - 2] == 10)) {
score += player[i];
}
score += player[i];
}

return score;
}
}

References

2660. Determine the Winner of a Bowling Game