292. Nim Game
来源:互联网 发布:lamp一键安装包ubuntu 编辑:程序博客网 时间:2024/06/15 16:56
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.
class Solution {
public:
bool canWinNim(int n) {
bool w;
if(n<3)
{
w=true;;
}
else if(n%4==0)
{
w=false;
}
else
{
w=true;
}
return w;
}
};
public:
bool canWinNim(int n) {
bool w;
if(n<3)
{
w=true;;
}
else if(n%4==0)
{
w=false;
}
else
{
w=true;
}
return w;
}
};
0 0
- [leetcode] 292.Nim Game
- 【LeetCode】292.Nim Game
- 292. Nim Game
- leetcode:292. Nim Game
- 292. Nim Game
- 292. Nim Game
- 292. Nim Game
- leetCode 292. Nim Game
- 292. Nim Game LeetCode
- 292. Nim Game
- LeetCode 292. Nim Game
- LeetCode 292. Nim Game
- LeetCode 292.Nim Game
- LeetCode 292. Nim Game
- 292. Nim Game
- 292. Nim Game
- 292. Nim Game
- 292. Nim Game
- Android中使用@hide成员
- Java中时间格式的转换
- HTTP和HTTPS详解
- Android面试系列之事件分发
- 资源分享-教程:linux下安装lnamp环境
- 292. Nim Game
- linux初学笔记(1)简单的登陆与使用
- 免费接口汇总
- LeetCode 241. Different Ways to Add Parentheses
- idea快捷键
- 154. Find Minimum in Rotated Sorted Array II
- Vulkan Programming Guide 第一章(3)
- nginx、cgi通信原理
- 初试Java