-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_2855.java
38 lines (34 loc) · 1.07 KB
/
_2855.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
33
34
35
36
37
38
package com.fishercoder.solutions.thirdthousand;
import java.util.ArrayList;
import java.util.List;
public class _2855 {
public static class Solution1 {
public int minimumRightShifts(List<Integer> nums) {
int shifts = 0;
do {
if (sorted(nums)) {
return shifts;
}
nums = shiftByOne(nums);
shifts++;
} while (shifts < nums.size());
return -1;
}
private List<Integer> shiftByOne(List<Integer> list) {
List<Integer> shifted = new ArrayList<>();
shifted.add(list.get(list.size() - 1));
for (int i = 0; i < list.size() - 1; i++) {
shifted.add(list.get(i));
}
return shifted;
}
private boolean sorted(List<Integer> nums) {
for (int i = 0; i < nums.size() - 1; i++) {
if (nums.get(i) >= nums.get(i + 1)) {
return false;
}
}
return true;
}
}
}