2660. Determine the Winner of a Bowling Game Easy
1/**
2 * [2660] Determine the Winner of a Bowling Game
3 *
4 * You are given two 0-indexed integer arrays <font face="monospace">player1</font> and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively.
5 * The bowling game consists of n turns, and the number of pins in each turn is exactly 10.
6 * Assume a player hits xi pins in the i^th turn. The value of the i^th turn for the player is:
7 *
8 * 2xi if the player hits 10 pins in either (i - 1)^th or (i - 2)^th turn.
9 * Otherwise, it is xi.
10 *
11 * The score of the player is the sum of the values of their n turns.
12 * Return
13 *
14 * 1 if the score of player 1 is more than the score of player 2,
15 * 2 if the score of player 2 is more than the score of player 1, and
16 * 0 in case of a draw.
17 *
18 *
19 * <strong class="example">Example 1:
20 * <div class="example-block">
21 * Input: <span class="example-io">player1 = [5,10,3,2], player2 = [6,5,7,3]</span>
22 * Output: <span class="example-io">1</span>
23 * Explanation:
24 * The score of player 1 is 5 + 10 + 2*3 + 2*2 = 25.
25 * The score of player 2 is 6 + 5 + 7 + 3 = 21.
26 * </div>
27 * <strong class="example">Example 2:
28 * <div class="example-block">
29 * Input: <span class="example-io">player1 = [3,5,7,6], player2 = [8,10,10,2]</span>
30 * Output: <span class="example-io">2</span>
31 * Explanation:
32 * The score of player 1 is 3 + 5 + 7 + 6 = 21.
33 * The score of player 2 is 8 + 10 + 2*10 + 2*2 = 42.
34 * </div>
35 * <strong class="example">Example 3:
36 * <div class="example-block">
37 * Input: <span class="example-io">player1 = [2,3], player2 = [4,1]</span>
38 * Output: <span class="example-io">0</span>
39 * Explanation:
40 * The score of player1 is 2 + 3 = 5.
41 * The score of player2 is 4 + 1 = 5.
42 * </div>
43 * <strong class="example">Example 4:
44 * <div class="example-block">
45 * Input: <span class="example-io">player1 = [1,1,1,10,10,10,10], player2 = [10,10,10,10,1,1,1]</span>
46 * Output: <span class="example-io">2</span>
47 * Explanation:
48 * The score of player1 is 1 + 1 + 1 + 10 + 2*10 + 2*10 + 2*10 = 73.
49 * The score of player2 is 10 + 2*10 + 2*10 + 2*10 + 2*1 + 2*1 + 1 = 75.
50 * </div>
51 *
52 * Constraints:
53 *
54 * n == player1.length == player2.length
55 * 1 <= n <= 1000
56 * 0 <= player1[i], player2[i] <= 10
57 *
58 */
59pub struct Solution {}
60
61// problem: https://leetcode.com/problems/determine-the-winner-of-a-bowling-game/
62// discuss: https://leetcode.com/problems/determine-the-winner-of-a-bowling-game/discuss/?currentPage=1&orderBy=most_votes&query=
63
64// submission codes start here
65
66impl Solution {
67 pub fn is_winner(player1: Vec<i32>, player2: Vec<i32>) -> i32 {
68 0
69 }
70}
71
72// submission codes end
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77
78 #[test]
79 fn test_2660() {
80 }
81}
82
Back
© 2025 bowen.ge All Rights Reserved.