292. Nim Game
2016-05-13 17:29
375 查看
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.
Answer with python:
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.
Answer with python:
lass Solution(object): def canWinNim(self, n): if n % 4 == 0: return False else: return True
相关文章推荐
- CSS
- 回来了
- 设计模式之装饰模式
- 谈谈对好代码的理解?
- 不错的移动站翻页效果
- 配置Tomcat使用https协议(配置SSL协议)
- Navicat连接Oracle详细教程
- Python 装饰器,@property 以及 Pycaffe.py
- 不重复随机数列生成算法2-数组有效位置的最后一个元素移动到当前位置
- 算法08 之堆
- doT.js 模板引擎的使用
- Google《Android性能优化》学习笔记
- gridview自动排序示例分享-自动排序
- SQL类型转换以及自动在前面补0满足10位工号标示法
- 欢迎使用CSDN-markdown编辑器
- Android开机自动启动应用
- Java中equals和==的区别
- linux tomcat配置https
- css 直角三角形 特殊三角形 对话气泡
- 01.Boost库安装及编译调试