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.
class Solution(object):
def canWinNim(self, n):
"""
:type n: int
:rtype: bool
"""
return bool(n%4)
1 bool()可以将参数转换成bool型,为什么要用bool函数,直接返回n%4不行吗?不行,因为n%4可以得到很多值,比如0,1,2,3,如果直接返回值,那返回的就是0,1,2,3,不是True和False了