- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1447.java
24 lines (21 loc) · 756 Bytes
/
_1447.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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.List;
publicclass_1447 {
publicstaticclassSolution1 {
publicList<String> simplifiedFractions(intn) {
List<String> result = newArrayList<>();
for (intdenominator = 2; denominator <= n; denominator++) {
for (intnominator = 1; nominator < denominator; nominator++) {
if (getGcd(nominator, denominator) == 1) {
result.add(nominator + "/" + denominator);
}
}
}
returnresult;
}
privateintgetGcd(inta, intb) {
returnb == 0 ? a : getGcd(b, a % b);
}
}
}