-
Notifications
You must be signed in to change notification settings - Fork 26
/
smallest.java
39 lines (38 loc) · 926 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
public class smallest {
public int smallest(int n) {
if (n == 0) {
return 0;
}
int res = 1;
boolean isCorrect = false;
while (!isCorrect) {
boolean allRight = true;
for (int i = 0; i < n; ) {
int num = res * ++i;
if (!contains2(num)) {
allRight = false;
break;
}
}
if (allRight) {
isCorrect = true;
} else {
res++;
}
}
return res;
}
private boolean contains2(int num) {
boolean contains2 = false;
while (num != 0) {
if (num % 10 == 2) {
contains2 = true;
num = 0;
break;
} else {
num /= 10;
}
}
return contains2;
}
}