#include <leetcode.h>
◆ bestRotation()
int leetcode::smallest_rotation_with_highest_score::Solution::bestRotation |
( |
vector< int > & | nums | ) |
|
|
static |
在文件 leetcode.cpp 第 4110 行定义.
4110 {
4111 const int n = nums.size();
4112 vector k_score_diff(n + 1, 0);
4113 for(
int i = 0; i <
n; i++) {
4114 const int low = (i + 1) % n;
4115 const int high = (i - nums[i] +
n) % n;
4116 k_score_diff[low]++;
4117 k_score_diff[high + 1]--;
4118 if(low > high) {
4119 k_score_diff[0]++;
4121 }
4122 }
4124 int max_score = 0;
4125 int score = 0;
4126 for(
int i = 0; i <
n; i++) {
4127 score += k_score_diff[i];
4128 if(score > max_score) {
4130 max_score = score;
4131 }
4132 }
4134 }
vector< vector< int > > ans
被这些函数引用 leetcode::smallest_rotation_with_highest_score::TEST() , 以及 leetcode::smallest_rotation_with_highest_score::TEST().
该类的文档由以下文件生成: