Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitba5cfeb

Browse files
authored
Add 1690 (#140)
* Add 1690* Fix checkstyleMain
1 parentc9ec779 commitba5cfeb

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
packagecom.fishercoder.solutions;
2+
3+
publicclass_1690 {
4+
publicstaticclassSolution1 {
5+
6+
int[]stonesRef;
7+
8+
int[]prepareSums;
9+
10+
int[][]maxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ =newint[1005][1005];
11+
12+
publicintstoneGameVII(int[]stones) {
13+
this.stonesRef =stones;
14+
inttotalStonesNumber =stones.length;
15+
this.prepareSums =newint[totalStonesNumber +1];
16+
for (inti =1;i <=totalStonesNumber;i++) {
17+
this.prepareSums[i] =this.prepareSums[i -1] +stones[i -1];
18+
}
19+
for (intlen =1;len <=totalStonesNumber;len++) {
20+
for (inti =1;i +len -1 <=totalStonesNumber;i++) {
21+
intj =i +len -1;
22+
this.setMaxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ(i,j);
23+
}
24+
}
25+
returnmaxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ[1][totalStonesNumber];
26+
}
27+
28+
privatevoidsetMaxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ(inti,intj) {
29+
if (j -i ==0) {
30+
maxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ[i][j] =0;
31+
}elseif (j -i ==1) {
32+
maxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ[i][j] =Math.max(stonesRef[i -1],stonesRef[j -1]);
33+
}else {
34+
maxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ[i][j] =Math.max(
35+
this.sumOfTheStonesValueInPosIToJ(i +1,j)
36+
-maxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ[i +1][j],
37+
this.sumOfTheStonesValueInPosIToJ(i,j -1)
38+
-maxDiffScoureBetweenTowPlayerWhenPlayInPosItoJ[i][j -1]);
39+
}
40+
}
41+
42+
privateintsumOfTheStonesValueInPosIToJ(inti,intj) {
43+
returnthis.prepareSums[j] -this.prepareSums[i -1];
44+
}
45+
}
46+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
packagecom.fishercoder;
2+
3+
importcom.fishercoder.solutions._1690;
4+
importorg.junit.BeforeClass;
5+
importorg.junit.Test;
6+
7+
importstaticorg.junit.Assert.assertEquals;
8+
9+
publicclass_1690Test {
10+
privatestatic_1690.Solution1solution1;
11+
12+
@BeforeClass
13+
publicstaticvoidsetup() {
14+
solution1 =new_1690.Solution1();
15+
}
16+
17+
@Test
18+
publicvoidtest1() {
19+
assertEquals(6,solution1.stoneGameVII(newint[]{5,3,1,4,2}));
20+
}
21+
22+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp