-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1025-DivisorGame.cs
36 lines (31 loc) · 964 Bytes
/
1025-DivisorGame.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//-----------------------------------------------------------------------------
// Runtime: 40ms
// Memory Usage: 14.6 MB
// Link: https://leetcode.com/submissions/detail/332566152/
//-----------------------------------------------------------------------------
namespace LeetCode
{
public class _1025_DivisorGame
{
public bool DivisorGame(int N)
{
if (N == 1) return false;
if (N == 2) return true;
var result = new bool[N + 1];
result[1] = false;
result[2] = true;
for (int i = 3; i <= N; i++)
{
var bobWin = true;
for (int j = 1; j <= i / 2; j++)
{
if (i % j == 0)
bobWin = bobWin && result[i - j];
if (!bobWin) break;
}
result[i] = !bobWin;
}
return result[N];
}
}
}