Skip to content

Commit 7fa9736

Browse files
committed
智力: 策略游戏C
Change-Id: I76e9adde09c42d1e1dc37c77138f454bb2818947
1 parent dc03ec9 commit 7fa9736

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

go/leetcode/292.nim-游戏.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* @lc app=leetcode.cn id=292 lang=golang
3+
*
4+
* [292] Nim 游戏
5+
*
6+
* https://leetcode-cn.com/problems/nim-game/description/
7+
*
8+
* algorithms
9+
* Easy (69.56%)
10+
* Likes: 231
11+
* Dislikes: 0
12+
* Total Accepted: 31.2K
13+
* Total Submissions: 44.9K
14+
* Testcase Example: '4'
15+
*
16+
* 你和你的朋友,两个人一起玩 Nim 游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头。 拿掉最后一块石头的人就是获胜者。你作为先手。
17+
*
18+
* 你们是聪明人,每一步都是最优解。 编写一个函数,来判断你是否可以在给定石头数量的情况下赢得游戏。
19+
*
20+
* 示例:
21+
*
22+
* 输入: 4
23+
* 输出: false
24+
* 解释: 如果堆中有 4 块石头,那么你永远不会赢得比赛;
25+
* 因为无论你拿走 1 块、2 块 还是 3 块石头,最后一块石头总是会被你的朋友拿走。
26+
*
27+
*
28+
*/
29+
30+
// @lc code=start
31+
func canWinNim(n int) bool {
32+
return n % 4 != 0
33+
}
34+
// @lc code=end
35+

0 commit comments

Comments
 (0)