LeetCode-Nim Game
2016-03-28 08:54
309 查看
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.
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.
public class Solution { public boolean canWinNim(int n) { // Just remember to handle the corner case. if (n==0) return true; if (n % 4 ==0){ return false; } else{ return true; } } }
相关文章推荐
- mysql 字符串处理
- C语言位域精解
- CodeForces 608B Hamming Distance Sum
- Filter
- 【phpcms-v9】模型字段文件夹下各个文件的作用
- Project configuration is not up-to-date with pom.xml
- 反转链表
- 深入Java集合HashMap实现原理
- springboot-Developer tools开发者福利
- 银线蕨-我的啊银
- 什么是并发控制中的2PL
- v$sga/v$sgainfo/v$sgastat
- 安装keras,教育网速度比较快
- 【phpcms-v9】phpcms-v9视频模型的添加
- OpenCV进阶之路:神经网络识别车牌字符
- bzoj 1043 下落的圆盘(计算几何-圆的周长并)
- LFCS 系列第一讲:如何在 Linux 上使用 GNU sed 等命令来创建、编辑和操作文件
- phpcms-v9】后台content模块的content.php控制器文件分析-后台添加内容代码分析
- 在.net中调用Delphi dll的Pchar转换
- hbase 读写数据