Skip to content

Commit 81d3d3d

Browse files
author
huang
committed
leetcode1025动态规划除数博弈
1 parent b04a8bc commit 81d3d3d

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

leetcode/DivisorGame1025.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* leetcode³ýÊý²©ÞÄ
3+
*/
4+
5+
public class DivisorGame1025{
6+
7+
public static void main(String[] args) {
8+
System.out.println(divisorGame(100));
9+
}
10+
11+
public static boolean divisorGame(int N) {
12+
13+
boolean r[] = new boolean[N];
14+
for (int i = 0; i <N ; i++) {
15+
r[i] = false;
16+
if (i == 0){
17+
r[i] = false;
18+
continue;
19+
}else if(i == 1) {
20+
r[i] = true;
21+
continue;
22+
}
23+
for (int j =1; j < (i+1)/2; j++) {
24+
if ((i+1) % j == 0) {
25+
if(!r[i-j]){
26+
r[i] = true;
27+
break;
28+
}
29+
}
30+
}
31+
32+
}
33+
return r[N-1];
34+
}
35+
}

0 commit comments

Comments
 (0)