algorithm notes: leetcode#292 nim game

Problem


Solution


Python implementation

1
2
3
4
5
6
7
class :
def canWinNim(self, n):
"""
:type n: int
:rtype: bool
"""
return n % 4 != 0

Java implementation

1
2
3
4
5
class {
public boolean canWinNim(int n) {
return n % 4 != 0;
}
}

Time complexity

O(1).

Space complexity

O(1).


292. Nim Game
(中文版) 算法笔记: 力扣#292 Nim游戏