Leetcode 1086 Solution
This article provides solution to leetcode question 1086 (divisor-game)
Access this page by simply typing in "lcs 1086" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/divisor-game
Solution
class Solution:
def divisorGame(self, N: int) -> bool:
self.m = {}
def dfs(N):
if N == 1:
return False
if N in self.m:
return self.m[N]
for i in range(1, N):
if N % i == 0 and not dfs(N - i):
self.m[N] = True
return True
self.m[N] = False
return False
return dfs(N)