leetcode:292. Nim 游戏(数学推理)

简介: leetcode:292. Nim 游戏(数学推理)

一、题目

函数原型:bool canWinNim(int n)

二、思路

通过数学推理,列举找规律,发现当石头数为4的倍数时,我会输掉游戏;而其他情况,我都会赢得游戏。

三、代码

bool canWinNim(int n){
    if(n%4==0)
        return false;
    else
        return true;
}


目录
相关文章
|
2月前
LeetCode题:174. 地下城游戏
LeetCode题:174. 地下城游戏
37 0
LeetCode题:174. 地下城游戏
|
3月前
|
Go
golang力扣leetcode 1823.找出游戏的获胜者
golang力扣leetcode 1823.找出游戏的获胜者
25 0
|
3月前
leetcode-1996:游戏中弱角色的数量
leetcode-1996:游戏中弱角色的数量
22 0
|
3月前
leetcode-1345:跳跃游戏 IV
leetcode-1345:跳跃游戏 IV
25 0
|
3月前
|
Go
golang力扣leetcode 1996.游戏中弱角色的数量
golang力扣leetcode 1996.游戏中弱角色的数量
22 0
|
3月前
|
算法
leetcode-390:消除游戏
leetcode-390:消除游戏
22 0
|
3月前
|
Go
golang力扣leetcode 45.跳跃游戏II
golang力扣leetcode 45.跳跃游戏II
12 0
|
12天前
|
算法
【力扣】55.跳跃游戏
【力扣】55.跳跃游戏
|
3月前
|
算法 Java 测试技术
[Java·算法·中等] LeetCode 45. 跳跃游戏 II 详细解读
[Java·算法·中等] LeetCode 45. 跳跃游戏 II 详细解读
28 0
|
3月前
leetcode-529:扫雷游戏
leetcode-529:扫雷游戏
21 0