-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp38.java
42 lines (32 loc) · 987 Bytes
/
p38.java
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
40
41
42
import java.util.*;
public class p38{
public static void main(String[] args){
int max = 0;
for (int i = 1; i < 10000; i++){
int pan = pan(i);
if (max < pan){max = pan;}
}
System.out.println(max);
}
private static int pan(int num){
StringBuilder build = new StringBuilder();
int count = 1;
while(build.length() < 9){
build.append(num * count);
count++;
}
if (build.length() == 9 && unique(build.toString())){return Integer.valueOf(build.toString());}
return 0;
}
//unique and has no zeros
private static boolean unique(String s){
int n = s.length();
Set<Character> letters = new HashSet<Character>();
for (int i = 0; i < n; i++){
char c = s.charAt(i);
if (c == '0'){return false;}
letters.add(c);
}
return letters.size() == n;
}
}