Skip to content

Commit 29fd5e4

Browse files
authored
Update 0877-stone-game.cpp
1 parent e187c7c commit 29fd5e4

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

cpp/0877-stone-game.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22
Alice and Bob play a game with piles of stones. There are an even number of piles arranged
33
in a row, and each pile has a positive integer number of stones piles[i].
44
5-
The objective of the game is to end with the most stones. The total number of stones across
5+
The objective of the game is to end with the most stones. The total number of stones across
66
all the piles is odd, so there are no ties.
77
8-
Alice and Bob take turns, with Alice starting first. Each turn, a player takes the entire pile
8+
Alice and Bob take turns, with Alice starting first. Each turn, a player takes the entire pile
99
of stones either from the beginning or from the end of the row. This continues until there are
1010
no more piles left, at which point the person with the most stones wins.
1111
12-
Assuming Alice and Bob play optimally, return true if Alice wins the game, or false if Bob wins.
12+
Assuming Alice and Bob play optimally, return true if Alice wins the game, or false if Bob wins.
1313
14-
Ex: Input: piles = [5,3,4,5]
15-
Output: true
16-
Explanation:
17-
Alice starts first, and can only take the first 5 or the last 5.
18-
Say she takes the first 5, so that the row becomes [3, 4, 5].
19-
If Bob takes 3, then the board is [4, 5], and Alice takes 5 to win with 10 points.
20-
If Bob takes the last 5, then the board is [3, 4], and Alice takes 4 to win with 9 points.
21-
This demonstrated that taking the first 5 was a winning move for Alice, so we return true.
14+
Ex: Input: piles = [5,3,4,5]
15+
Output: true
16+
Explanation:
17+
Alice starts first, and can only take the first 5 or the last 5.
18+
Say she takes the first 5, so that the row becomes [3, 4, 5].
19+
If Bob takes 3, then the board is [4, 5], and Alice takes 5 to win with 10 points.
20+
If Bob takes the last 5, then the board is [3, 4], and Alice takes 4 to win with 9 points.
21+
This demonstrated that taking the first 5 was a winning move for Alice, so we return true.
2222
2323
Space: O(n/2)
2424
Time : O(1)

0 commit comments

Comments
 (0)