forked from chicuongit913/MumTestJavaExam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmallest.java
59 lines (46 loc) · 837 Bytes
/
smallest.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package mumTestPackage;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import sun.tools.jar.resources.jar;
class MumTest32 {
@Test
void test() {
assertEquals(12, smallest(2));
assertEquals(624, smallest(4));
assertEquals(4062, smallest(7));
}
int smallest(int n) {
if(n <= 0) {
return 0;
}
int i = 1;
int digit = 2;
while (i < Integer.MAX_VALUE) {
if(isExistDigit(i, digit)) {
int j = 1;
int count = 0;
while (j <= n) {
if(isExistDigit(i*j, digit)) {
count++;
} else {
break;
}
j++;
}
if(count == n) {
return i;
}
}
i++;
}
return 0;
}
boolean isExistDigit(int n, int digit) {
while (n > 0) {
if(n % 10 == digit)
return true;
n /=10;
}
return false;
}
}