- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1752.java
31 lines (28 loc) · 909 Bytes
/
_1752.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
packagecom.fishercoder.solutions.secondthousand;
importjava.util.Arrays;
publicclass_1752 {
publicstaticclassSolution1 {
publicbooleancheck(int[] nums) {
int[] copy = Arrays.copyOf(nums, nums.length);
Arrays.sort(copy);
for (inti = 1; i <= nums.length; i++) {
int[] rotated = rotate(nums, i);
if (Arrays.equals(rotated, copy)) {
returntrue;
}
}
returnfalse;
}
privateint[] rotate(int[] nums, intstart) {
int[] rotated = newint[nums.length];
intj = 0;
for (inti = start; i < nums.length; i++, j++) {
rotated[j] = nums[i];
}
for (inti = 0; i < start; i++) {
rotated[j++] = nums[i];
}
returnrotated;
}
}
}