接外包,有相关需求的可以联系我:Telegram | Email

Stone Game

该文章创建(更新)于04/6/2022,请注意文章的时效性!

文章目录[隐藏]

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                    

要不赞赏一下?

微信
支付宝
PayPal
Bitcoin

版权声明 | Copyright

除非特别说明,本博客所有作品均采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。转载请注明转自-
https://www.emperinter.info/2022/04/06/stone-game/


要不聊聊?

我相信你准备留下的内容是经过思考的!【勾选防爬虫,未勾选无法留言】

*

*



YouTube | B站

微信公众号

👉 NewsLetter ❤️ 邮箱订阅 👈

优惠码

阿里云国际版20美元
Vultr10美元
搬瓦工 | Bandwagon应该有折扣吧?
Just My SocksJMS9272283 【注意手动复制去跳转】
域名 | namesiloemperinter(1美元)
币安 币安