forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1806.java
32 lines (30 loc) · 927 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
package com.fishercoder.solutions;
import java.util.Arrays;
public class _1806 {
public static class Solution1 {
public int reinitializePermutation(int n) {
int[] initial = new int[n];
int[] perm = new int[n];
for (int i = 0; i < n; i++) {
initial[i] = i;
perm[i] = i;
}
int[] arr = new int[n];
int times = 0;
do {
for (int i = 0; i < n; i++) {
if (i % 2 == 0) {
arr[i] = perm[i / 2];
} else {
arr[i] = perm[n / 2 + (i - 1) / 2];
}
}
times++;
for (int i = 0; i < n; i++) {
perm[i] = arr[i];
}
} while (!Arrays.equals(arr, initial));
return times;
}
}
}