292. Nim Game(easy)
You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone will be the winner. You will take the first turn to remove the stones.
Both of you are very clever and have optimal strategies for the game. Write a function to determine whether you can win the game given the number of stones in the heap.
For example, if there are 4 stones in the heap, then you will never win the game: no matter 1, 2, or 3 stones you remove, the last stone will always be removed by your friend.
/*
1: 赢
2: 赢
3: 赢
4: 不赢
5: 赢
6: 赢
7: 赢
8: 不赢
*/
class Solution {
public:
bool canWinNim(int n) {
if (n % == ){
return false;
}else{
return true;
}
}
};
好像很简单的样子。。
292. Nim Game(easy)的更多相关文章
- LeetCode: 292 Nim Game(easy)
题目: You are playing the following Nim Game with your friend: There is a heap of stones on the table, ...
- 292. Nim Game
292. Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on ...
- LN : leetcode 292 Nim Game
lc 292 Nim Game 292 Nim Game You are playing the following Nim Game with your friend: There is a hea ...
- 292. Nim Game(C++)
292. Nim Game(C++) You are playing the following Nim Game with your friend: There is a heap of stone ...
- LeetCode Javascript实现 344. Reverse String 292. Nim Game 371. Sum of Two Integers
344. Reverse String /** * @param {string} s * @return {string} */ var reverseString = function(s) { ...
- 【Leetcode】292. Nim Game
problem 292. Nim Game solution class Solution { public: bool canWinNim(int n) { ; } }; 来generalize一下 ...
- 292. Nim游戏
292. Nim游戏 class Solution(object): def canWinNim(self, n): """ :type n: int :rtype: b ...
- lintcode 394. Coins in a Line 、leetcode 292. Nim Game 、lintcode 395. Coins in a Line II
变型:如果是最后拿走所有石子那个人输,则f[0] = true 394. Coins in a Line dp[n]表示n个石子,先手的人,是必胜还是必输.拿1个石子,2个石子之后都是必胜,则当前必败 ...
- Java实现 LeetCode 292 Nim游戏
292. Nim 游戏 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解 ...
随机推荐
- 第54章 身份资源 - Identity Server 4 中文文档(v1.0.0)
此类为身份资源建模. Enabled 指示此资源是否已启用且可以请求.默认为true. Name 标识资源的唯一名称.这是客户端将用于授权请求中的scope参数的值. DisplayName 该值将用 ...
- [PHP] 邮件发送mail()函数失败问题 sendmail命令与postfix
1. php的mail()函数是可以发送邮件的 , 但是一直就没有测试成功过 , 现在总结一下原因 : php的mail函数 基于sendmail命令来发送 , sendmail命令需要安装postf ...
- [日常] nginx记录post数据
1.使用log_format指令来更改日志格式,该指令只能放在http{}段 log_format 日志名 '日志内容'; server { access_log /var/log/nginx/d ...
- [leetcode](4.21)4. 有效子数组的数目
给定一个整数数组 A,返回满足下面条件的 非空.连续 子数组的数目: 子数组中,最左侧的元素不大于其他元素. 示例 1: 输入:[1,4,2,5,3] 输出:11 解释:有 11 个有效子数组,分别是 ...
- checkbox在vue中的用法小结
关于checkbox多选框是再常见不过的了,几乎很多地方都会用到,这两天在使用vue框架时需要用到checkbox多选功能,实在着实让我头疼,vue和原生checkbox用法不太一样,之前对于vue插 ...
- apply,call和bind的用法区别
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- set用法小结
set本质上是一棵红黑树,用法也就那么几个,插入删除lowerbound,再就是迭代器之类的 基本用法 begin()--返回指向第一个元素的迭代器 #include<cstdio> #i ...
- 使用 Nexus Repository Manager 搭建 npm 私服
目录 环境 下载与安装 添加npm仓库 配置与验证npm仓库 发布自己的包 Nexus开启启动 脚注 环境 windows10(1803) Nexus Repository Manager OSS 3 ...
- MongoDB更需要好的模式设计 及 案例赏析
一 挑战 设计从来就是个挑战. 当我们第一次接触数据库,学习数据库基础理论时,都需要学习范式,老师也一再强调范式是设计的基础.范式是这门课程中的重要部分,在期末考试中也一定是个重要考点.如果我们当年 ...
- FIDDLER的使用方法及技巧总结
转自: https://www.cnblogs.com/ink-marks/p/6363275.html 一.FIDDLER快速入门及使用场景 Fiddler的官方网站:http://www.fidd ...