- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1387.java
31 lines (28 loc) · 893 Bytes
/
_1387.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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.List;
publicclass_1387 {
publicstaticclassSolution1 {
publicintgetKth(intlo, inthi, intk) {
List<int[]> power = newArrayList<>();
for (inti = lo; i <= hi; i++) {
power.add(newint[] {getSteps(i), i});
}
Collections.sort(power, (a, b) -> a[0] != b[0] ? a[0] - b[0] : a[1] - b[1]);
returnpower.get(k - 1)[1];
}
privateintgetSteps(intnumber) {
intsteps = 0;
while (number != 1) {
if (number % 2 == 0) {
number /= 2;
} else {
number = 3 * number + 1;
}
steps++;
}
returnsteps;
}
}
}