Skip to content

Commit 435aef3

Browse files
add 1806
1 parent 5c67f83 commit 435aef3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|1806|[Minimum Number of Operations to Reinitialize a Permutation](https://leetcode.com/problems/minimum-number-of-operations-to-reinitialize-a-permutation/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1806.java) ||Medium|Array, Greedy|
1112
|1805|[Number of Different Integers in a String](https://leetcode.com/problems/number-of-different-integers-in-a-string/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1805.java) ||Medium|String|
1213
|1800|[Maximum Ascending Subarray Sum](https://leetcode.com/problems/maximum-ascending-subarray-sum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1800.java) ||Easy|Two Pointers|
1314
|1797|[Design Authentication Manager](https://leetcode.com/problems/design-authentication-manager/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1797.java) ||Medium|HashTable, Design|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _1806 {
6+
public static class Solution1 {
7+
public int reinitializePermutation(int n) {
8+
int[] initial = new int[n];
9+
int[] perm = new int[n];
10+
for (int i = 0; i < n; i++) {
11+
initial[i] = i;
12+
perm[i] = i;
13+
}
14+
int[] arr = new int[n];
15+
int times = 0;
16+
do {
17+
for (int i = 0; i < n; i++) {
18+
if (i % 2 == 0) {
19+
arr[i] = perm[i / 2];
20+
} else {
21+
arr[i] = perm[n / 2 + (i - 1) / 2];
22+
}
23+
}
24+
times++;
25+
for (int i = 0; i < n; i++) {
26+
perm[i] = arr[i];
27+
}
28+
} while (!Arrays.equals(arr, initial));
29+
return times;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)