标签:
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.
Hint:
public class Solution { public boolean canWinNim(int n) { //If 1,2,3 you win. //If 4 you lose. //If 5,6,7, you can make it into 4, and let the opponent lose return n%4 != 0; } }
标签:
原文地址:http://www.cnblogs.com/neweracoding/p/5631698.html