每日一题困难题 学习一下题解 似懂非懂 呜呜呜 焦虑(把csdn当日记哈哈哈 日常emo)
java:
class Solution {
public int bestRotation(int[] nums) {
int n = nums.length;
int[] differs = new int[n];
for(int i = 0; i < n ; i++){
int low = (i + n) % n;
int high = (i + n + 1 - nums[i]) % n;
differs[low]++;
differs[high]--;
if(differs[low] >= differs[high]){
differs[0]++;
}
}
int ans = 0;
int score = 0;
int maxscore = 0;
for(int i = 0; i < n; i++){
score += differs[i];
if(score > maxscore){
ans = i;
score = maxscore;
}
}
return ans;
}
}