Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit435aef3

Browse files
add 1806
1 parent5c67f83 commit435aef3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.Arrays;
4+
5+
publicclass_1806 {
6+
publicstaticclassSolution1 {
7+
publicintreinitializePermutation(intn) {
8+
int[]initial =newint[n];
9+
int[]perm =newint[n];
10+
for (inti =0;i <n;i++) {
11+
initial[i] =i;
12+
perm[i] =i;
13+
}
14+
int[]arr =newint[n];
15+
inttimes =0;
16+
do {
17+
for (inti =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 (inti =0;i <n;i++) {
26+
perm[i] =arr[i];
27+
}
28+
}while (!Arrays.equals(arr,initial));
29+
returntimes;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp