Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

1025. 除数博弈 #29

Open
AmelloAster opened this issue Jul 24, 2020 · 0 comments
Open

1025. 除数博弈 #29

AmelloAster opened this issue Jul 24, 2020 · 0 comments
Labels
Easy 史莱姆 Finished 经验+1 Leetcode daily topic 每日药丸 金金 Code is life

Comments

@AmelloAster
Copy link
Collaborator

AmelloAster commented Jul 24, 2020

1025. 除数博弈

爱丽丝和鲍勃一起玩游戏,他们轮流行动。爱丽丝先手开局。

最初,黑板上有一个数字 N 。在每个玩家的回合,玩家需要执行以下操作:

选出任一 x,满足 0 < x < N 且 N % x == 0 。
用 N - x 替换黑板上的数字 N 。
如果玩家无法执行这些操作,就会输掉游戏。

只有在爱丽丝在游戏中取得胜利时才返回 True,否则返回 false。假设两个玩家都以最佳状态参与游戏。

 

示例 1:

输入:2
输出:true
解释:爱丽丝选择 1,鲍勃无法进行操作。

示例 2:

输入:3
输出:false
解释:爱丽丝选择 1,鲍勃也选择 1,然后爱丽丝无法进行操作。

 

提示:

1 <= N <= 1000

解题代码

var divisorGame = function (N) {
    return N % 2 === 0;
};

解题思路

A先手 N为奇数时 A 的回合N永远是奇数 B的回合永远是偶数 所以B必赢
反之 A 必赢

代码效率

执行用时:
96 ms, 在所有 JavaScript 提交中击败了6.85%的用户
内存消耗:
37.4 MB, 在所有 JavaScript 提交中击败了100.00%的用户
@AmelloAster AmelloAster added Easy 史莱姆 Finished 经验+1 Leetcode daily topic 每日药丸 金金 Code is life labels Jul 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Easy 史莱姆 Finished 经验+1 Leetcode daily topic 每日药丸 金金 Code is life
Projects
None yet
Development

No branches or pull requests

1 participant