Home Nim Game
Post
Cancel

Nim Game

Leetcode Problem

Nim Game

Nim game에서 n개의 stone이 주어졌을 때 이길 수 있는 경우를 판별하는 문제입니다.

1
2
3
class Solution:
    def canWinNim(self, n: int) -> bool:
        return False if n % 4 == 0 else True

경우의 수를 1부터 차례대로 계산하다보면 4의 배수가 되는 경우만 지는 경우가 생긴다는 것을 알게 됩니다.





참고

This post is licensed under CC BY 4.0 by the author.