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

Commitda14ca3

Browse files
refactor 625
1 parent6a9e043 commitda14ca3

File tree

1 file changed

+30
-26
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+30
-26
lines changed

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

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,38 +24,42 @@
2424
*/
2525
publicclass_625 {
2626

27-
/**reference: https://discuss.leetcode.com/topic/92854/java-solution-result-array
28-
* and https://leetcode.com/articles/minimum-factorization/#approach-3-using-factorizationaccepted*/
29-
publicintsmallestFactorization(inta) {
30-
//case 1: a < 10
31-
if (a <10) {
32-
returna;
33-
}
34-
35-
//case 2: start with 9 and try every possible digit
36-
List<Integer>resultArray =newArrayList<>();
37-
for (inti =9;i >1;i--) {
38-
//if current digit divides a, then store all occurences of current digit in res
39-
while (a %i ==0) {
40-
a =a /i;
41-
resultArray.add(i);
27+
publicstaticclassSolution1 {
28+
/**
29+
* reference: https://discuss.leetcode.com/topic/92854/java-solution-result-array
30+
* and https://leetcode.com/articles/minimum-factorization/#approach-3-using-factorizationaccepted
31+
*/
32+
publicintsmallestFactorization(inta) {
33+
//case 1: a < 10
34+
if (a <10) {
35+
returna;
4236
}
43-
}
4437

45-
//if a could not be broken in form of digits, return 0
46-
if (a !=0) {
47-
return0;
48-
}
38+
//case 2: start with 9 and try every possible digit
39+
List<Integer>resultArray =newArrayList<>();
40+
for (inti =9;i >1;i--) {
41+
//if current digit divides a, then store all occurences of current digit in res
42+
while (a %i ==0) {
43+
a =a /i;
44+
resultArray.add(i);
45+
}
46+
}
4947

50-
//get the result from the result array in reverse order
51-
longresult =0;
52-
for (inti =resultArray.size() -1;i >=0;i--) {
53-
result =result *10 +resultArray.get(i);
54-
if (result >Integer.MAX_VALUE) {
48+
//if a could not be broken in form of digits, return 0
49+
if (a !=0) {
5550
return0;
5651
}
52+
53+
//get the result from the result array in reverse order
54+
longresult =0;
55+
for (inti =resultArray.size() -1;i >=0;i--) {
56+
result =result *10 +resultArray.get(i);
57+
if (result >Integer.MAX_VALUE) {
58+
return0;
59+
}
60+
}
61+
return (int)result;
5762
}
58-
return (int)result;
5963
}
6064

6165
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp