1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| class Solution { public boolean divisorGame(int N) {
boolean[] dp = new boolean[N + 1]; if (N == 1) { return false; } if (N == 2) { return true; } if (N == 3) { return false; } dp[1] = false; dp[2] = true; dp[3] = false;
for (int i = 4; i <= N; i++) { dp[i] = !dp[i - 1]; } return dp[N]; } }
|