- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1806.java
32 lines (30 loc) · 942 Bytes
/
_1806.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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.Arrays;
publicclass_1806 {
publicstaticclassSolution1 {
publicintreinitializePermutation(intn) {
int[] initial = newint[n];
int[] perm = newint[n];
for (inti = 0; i < n; i++) {
initial[i] = i;
perm[i] = i;
}
int[] arr = newint[n];
inttimes = 0;
do {
for (inti = 0; i < n; i++) {
if (i % 2 == 0) {
arr[i] = perm[i / 2];
} else {
arr[i] = perm[n / 2 + (i - 1) / 2];
}
}
times++;
for (inti = 0; i < n; i++) {
perm[i] = arr[i];
}
} while (!Arrays.equals(arr, initial));
returntimes;
}
}
}