Leetcode-1025. Divisor Game

Original link: https://leetcode.com/problems/divisor-game/

The code is super stupid.

class Solution(object):
    def divisorGame(self, N):
        """
        :type N: int
        :rtype: bool
        """
      return N % 2 == 0  

The point here is to mathmatically prove that we can do that here.

We have

  1. Odd = 1 * odd * odd * … * odd
  2. Even = 1 * … * even

So for people who has an odd, he have to return an even (Odd - odd = even)
For people who has an even, he have two choices.

We know that if Alice has 3, she will lose. But if she has 2 or 4, she will win.

So we can design a strategy which is for Alice, always try to gives odd. As the number is decreasing, the number given by Bob is always even and will finally be 4.

But if Aice gets an odd first, she has no choice but gives an even. Bob will take the same strategy to give an odd again and finally win.

So what we care is only whether the first number for Alice is Even.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值