class Solution(object): def canWinNim(self, n): if n % 4 is not 0: return True else: return False
Or in one line:
def canWinNim(self, n): return n % 4 != 0
Also your use of "is" is probably not intended. You aren't checking for identity between the integer objects 0 and n % 4, but the equality of their values. This will work sometimes (I believe) thanks to caching, but is not 100% guaranteed to work always.
You phrased it wrong, they are checking for identity and not for equality. Likely it works for -5 to 256, but I don't know about a guarantee, either. And it's definitely a bad idea unless it's used on purpose and for a good reason, which I doubt here as well :-)
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.