#1140
Stone Game II
pupil · 550 · lc medium +28 · 72.9% accepted · 3,438 likes · top 83%
Description
Alice and Bob play a game with stone piles arranged in a row (piles[i] stones). They alternate turns (Alice first). On each turn, the player takes all stones from the first X remaining piles, where 1 <= X <= 2M, then updates M = max(M, X). Initially M = 1.
Both play optimally. Return the maximum number of stones Alice can collect.
Code
1
2
3