Skip to content

Instantly share code, notes, and snippets.

@wushbin
Created April 1, 2020 04:51
Show Gist options
  • Select an option

  • Save wushbin/cce4a129fe5f3d8eb550e87eb5421310 to your computer and use it in GitHub Desktop.

Select an option

Save wushbin/cce4a129fe5f3d8eb550e87eb5421310 to your computer and use it in GitHub Desktop.
class Solution {
public int maxRotateFunction(int[] A) {
int sum = 0;
int F = 0;
int len = A.length;
for (int i = 0; i < len; i++) {
sum += A[i];
F += i * A[i];
}
int res = F;
for (int i = 1; i < len; i++) {
F = F + sum - len * A[len - i];
res = Math.max(res, F);
}
return res;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment