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

Commit955b4d9

Browse files
refactor 650
1 parent23e60ed commit955b4d9

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

‎src/main/java/com/fishercoder/solutions/_650.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@
2424
*/
2525
publicclass_650 {
2626

27-
publicintminSteps(intn) {
28-
int[]dp =newint[n +1];
29-
for (inti =2;i <=n;i++) {
30-
dp[i] =i;//we assign i to dp[i] first, because for a lot of cases, e.g. for most cases when i is odd, its min steps is i itself, if it's not, we can overwrite it later
31-
for (intj =i -1;j >1;j--) {
32-
//traverse backwards, whenever it's divisible by j, we'll update dp[i] because it's guaranteed to be smaller when j is smaller.
33-
if (i %j ==0) {
34-
dp[i] =dp[j] + (i /j);
35-
break;
27+
publicstaticclassSolution1 {
28+
publicintminSteps(intn) {
29+
int[]dp =newint[n +1];
30+
for (inti =2;i <=n;i++) {
31+
dp[i] =i;//we assign i to dp[i] first, because for a lot of cases, e.g. for most cases when i is odd, its min steps is i itself, if it's not, we can overwrite it later
32+
for (intj =i -1;j >1;j--) {
33+
//traverse backwards, whenever it's divisible by j, we'll update dp[i] because it's guaranteed to be smaller when j is smaller.
34+
if (i %j ==0) {
35+
dp[i] =dp[j] + (i /j);
36+
break;
37+
}
3638
}
3739
}
40+
returndp[n];
3841
}
39-
returndp[n];
4042
}
4143
}

‎src/test/java/com/fishercoder/_650Test.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,35 +7,35 @@
77
importstaticorg.junit.Assert.assertEquals;
88

99
publicclass_650Test {
10-
privatestatic_650test;
10+
privatestatic_650.Solution1solution1;
1111

1212
@BeforeClass
1313
publicstaticvoidsetup() {
14-
test =new_650();
14+
solution1 =new_650.Solution1();
1515
}
1616

1717
@Test
1818
publicvoidtest1() {
19-
assertEquals(3,test.minSteps(3));
19+
assertEquals(3,solution1.minSteps(3));
2020
}
2121

2222
@Test
2323
publicvoidtest2() {
24-
assertEquals(9,test.minSteps(20));
24+
assertEquals(9,solution1.minSteps(20));
2525
}
2626

2727
@Test
2828
publicvoidtest3() {
29-
assertEquals(19,test.minSteps(19));
29+
assertEquals(19,solution1.minSteps(19));
3030
}
3131

3232
@Test
3333
publicvoidtest4() {
34-
assertEquals(0,test.minSteps(1));
34+
assertEquals(0,solution1.minSteps(1));
3535
}
3636

3737
@Test
3838
publicvoidtest5() {
39-
assertEquals(35,test.minSteps(741));
39+
assertEquals(35,solution1.minSteps(741));
4040
}
4141
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp