Skip to content

Commit da14ca3

Browse files
refactor 625
1 parent 6a9e043 commit da14ca3

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
public class _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-
public int smallestFactorization(int a) {
30-
//case 1: a < 10
31-
if (a < 10) {
32-
return a;
33-
}
34-
35-
//case 2: start with 9 and try every possible digit
36-
List<Integer> resultArray = new ArrayList<>();
37-
for (int i = 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+
public static class Solution1 {
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+
public int smallestFactorization(int a) {
33+
//case 1: a < 10
34+
if (a < 10) {
35+
return a;
4236
}
43-
}
4437

45-
//if a could not be broken in form of digits, return 0
46-
if (a != 0) {
47-
return 0;
48-
}
38+
//case 2: start with 9 and try every possible digit
39+
List<Integer> resultArray = new ArrayList<>();
40+
for (int i = 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-
long result = 0;
52-
for (int i = 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
return 0;
5651
}
52+
53+
//get the result from the result array in reverse order
54+
long result = 0;
55+
for (int i = resultArray.size() - 1; i >= 0; i--) {
56+
result = result * 10 + resultArray.get(i);
57+
if (result > Integer.MAX_VALUE) {
58+
return 0;
59+
}
60+
}
61+
return (int) result;
5762
}
58-
return (int) result;
5963
}
6064

6165
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy