-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProblem_038.java
More file actions
39 lines (31 loc) · 869 Bytes
/
Problem_038.java
File metadata and controls
39 lines (31 loc) · 869 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package euler;
public class Problem_038 {
static String largestPandigitalMultiple() {
String largest = "0";
for(int i = 1; i < 10000; i++) {
String concat = multipleConcat(i);
if(isPandigital(concat) && Integer.parseInt(largest) < Integer.parseInt(concat)) {
largest = concat;
}
}
return largest;
}
private static String multipleConcat(int n) {
String concat = "";
int counter = 1;
while(concat.length() < 9) {
concat += (n * counter++);
}
return concat;
}
private static boolean isPandigital(String s) {
if(s.length() != 9) return false;
if(s.contains("0")) return false;
for(int i = 1; i <= 9; i++) {
if(s.length() - s.replaceAll(Integer.toString(i), "").length() != 1)
return false;
}
// System.out.println(s);
return true;
}
}