forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_1752.java
31 lines (28 loc) · 894 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
package com.fishercoder.solutions;
import java.util.Arrays;
public class _1752 {
public static class Solution1 {
public boolean check(int[] nums) {
int[] copy = Arrays.copyOf(nums, nums.length);
Arrays.sort(copy);
for (int i = 1; i <= nums.length; i++) {
int[] rotated = rotate(nums, i);
if (Arrays.equals(rotated, copy)) {
return true;
}
}
return false;
}
private int[] rotate(int[] nums, int start) {
int[] rotated = new int[nums.length];
int j = 0;
for (int i = start; i < nums.length; i++, j++) {
rotated[j] = nums[i];
}
for (int i = 0; i < start; i++) {
rotated[j++] = nums[i];
}
return rotated;
}
}
}