Determine the Winner of a Bowling Game — LeetCode 2660 Python Solution
EasyArraySimulation
- Problem
- #2660
- 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
Python
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
| Measure | Complexity |
|---|---|
| Time | O(n), where n is the length of the array |
| Space | O(1) auxiliary |
Related problems
LeetCode 495Teemo AttackingEasyLeetCode 985Sum of Even Numbers After QueriesMediumLeetCode 1389Create Target Array in the Given OrderEasyLeetCode 1409Queries on a Permutation With KeyMediumLeetCode 1503Last Moment Before All Ants Fall Out of a PlankMediumLeetCode 1535Find the Winner of an Array GameMedium
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.