Stone Game

# Description

Alice and Bob play a game with piles of stones. There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].

The objective of the game is to end with the most stones. The total number of stones across all the piles is odd, so there are no ties.

Alice and Bob take turns, with Alice starting first. Each turn, a player takes the entire pile of stones either from the beginning or from the end of the row. This continues until there are no more piles left, at which point the person with the most stones wins.

Assuming Alice and Bob play optimally, return true if Alice wins the game, or false if Bob wins.

# Solution

• Both of them must be smart
• The only results between Win And Tie if Alice go frist.
• we just need to count the sum number of single and double index.
• take the biggest one.

# Code

``````class Solution:
def stoneGame(self, piles: List[int]) -> bool:
# base condition
if len(piles) == 2:
return True

s = 0
d = 0

for x in range(0,len(piles),2):
d = d + piles[x]
s = s + piles[x + 1]

if s != d:
return True
else:
return False
``````

# 👇 Share | 分享 👇

### 要不赞赏一下?  微信  支付宝  PayPal  Bitcoin

``https://www.emperinter.info/2022/04/06/stone-game/``

## My Github Contributions 