-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoEights.java
More file actions
29 lines (25 loc) · 804 Bytes
/
NoEights.java
File metadata and controls
29 lines (25 loc) · 804 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
import java.util.ArrayList;
import java.util.List;
public class NoEights {
public static int smallestAmount(int low, int high) {
List<Integer> lowDigits = getDigits(low);
List<Integer> highDigits = getDigits(high);
int commonDigitCount = Math.min(lowDigits.size(), highDigits.size());
int sharedEights = 0;
for (int digit = 0; digit < commonDigitCount; digit++)
{
if (lowDigits.get(digit) == 8 && highDigits.get(digit) == 8) {
sharedEights++;
}
}
return sharedEights;
}
private static List<Integer> getDigits(int i) {
List<Integer> digits = new ArrayList();
while (i > 0) {
digits.add(i % 10);
i /= 10;
}
return digits;
}
}