Given an array of integers A and let n to be its length.
Assume Bk to be an array obtained by rotating the array A k positions clock-wise, we define a “rotation function” F on A as follow:
F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1].
Calculate the maximum value of F(0), F(1), …, F(n-1).
Note:
n is guaranteed to be less than 105.
Example:
A = [4, 3, 2, 6]
F(0) = (0 * 4) + (1 * 3) + (2 * 2) + (3 * 6) = 0 + 3 + 4 + 18 = 25
F(1) = (0 * 6) + (1 * 4) + (2 * 3) + (3 * 2) = 0 + 4 + 6 + 6 = 16
F(2) = (0 * 2) + (1 * 6) + (2 * 4) + (3 * 3) = 0 + 6 + 8 + 9 = 23
F(3) = (0 * 3) + (1 * 2) + (2 * 6) + (3 * 4) = 0 + 2 + 12 + 12 = 26
So the maximum value of F(0), F(1), F(2), F(3) is F(3) = 26.

给定一个整数数组A,其长度为n,定义一个旋转函数F,它计算F(0), F(1), ..., F(n-1)的最大值。例如,对于数组[1,2,3,4],F(3) = 26。通过分析F(k)的规律,可以找到求解最值的方法。"
108257835,9228493,Scala编程:深入理解变量、数据类型与类型转换,"['Scala编程', '强类型语言', '类型转换', '变量声明']
订阅专栏 解锁全文
278

被折叠的 条评论
为什么被折叠?



