2660. 保龄球游戏的获胜者

2660. 保龄球游戏的获胜者

解法一: 模拟

go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
func isWinner(player1 []int, player2 []int) int {
player1Score := calcScore(player1)
player2Score := calcScore(player2)
if player1Score == player2Score {
return 0
} else if player1Score > player2Score {
return 1
}
return 2
}

func calcScore(player []int) int {
sum := 0
counter := 0
for _, score := range player {
sum += score
if counter > 0 {
counter--
sum += score
}
if score == 10 {
counter = 2
}
}
return sum
}
作者

wuhunyu

发布于

2023-12-27

更新于

2023-12-27

许可协议