problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::smallest_rotation_with_highest_score::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static int bestRotation (vector< int > &nums)
 

详细描述

在文件 leetcode.h1588 行定义.

成员函数说明

◆ bestRotation()

int leetcode::smallest_rotation_with_highest_score::Solution::bestRotation ( vector< int > &  nums)
static

在文件 leetcode.cpp4110 行定义.

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]++;
4120 k_score_diff[n]--;
4121 }
4122 }
4123 int ans = 0;
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) {
4129 ans = i;
4130 max_score = score;
4131 }
4132 }
4133 return ans;
4134 }

被这些函数引用 leetcode::smallest_rotation_with_highest_score::TEST().


该类的文档由以下文件生成: