EasyNo. 2660
Determine the Winner of a Bowling Game — LeetCode 2660 Python Solution
- Topics
- Array, Simulation
- Reading time
- 2 min
- Source
- leetcode.com
The problem
You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively. The bowling game consists of n turns, and the number of pins in each turn is exactly 10.
Python solution
class Solution:
def isWinner(self, player1: List[int], player2: List[int]) -> int:
def f(arr: List[int]) -> int:
s = 0
for i, x in enumerate(arr):
k = 2 if (i and arr[i - 1] == 10) or (i > 1 and arr[i - 2] == 10) else 1
s += k * x
return s
a, b = f(player1), f(player2)
return 1 if a > b else (2 if b > a else 0)Complexity
- Time
- O(n)where n is the length of the array
- Space · auxiliary
- O(1)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 0495 | Teemo Attacking | Easy |
| 0985 | Sum of Even Numbers After Queries | Medium |
| 1389 | Create Target Array in the Given Order | Easy |
| 1409 | Queries on a Permutation With Key | Medium |
| 1503 | Last Moment Before All Ants Fall Out of a Plank | Medium |
| 1535 | Find the Winner of an Array Game | Medium |
Frequently asked questions
- How hard is LeetCode 2660. Determine the Winner of a Bowling Game?
LeetCode 2660. Determine the Winner of a Bowling Game is rated Easy on LeetCode.
- What is the time complexity of LeetCode 2660. Determine the Winner of a Bowling Game?
The Python solution on this page runs in O(n), where n is the length of the array.
- What is the space complexity of LeetCode 2660. Determine the Winner of a Bowling Game?
The Python solution on this page uses O(1) auxiliary space.
- What topics does LeetCode 2660. Determine the Winner of a Bowling Game cover?
LeetCode 2660. Determine the Winner of a Bowling Game is tagged Array and Simulation on LeetCode.