396. Rotate Function

Given an array of integersAand letnto be its length.
AssumeBkto be an array obtained by rotating the arrayAkpositions clock-wise, we define a "rotation function"FonAas follow:
F(k) = 0 * Bk[0] + 1 * Bk[1] + ... + (n-1) * Bk[n-1].
Calculate the maximum value ofF(0), F(1), ..., F(n-1).
Note:
nis 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.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 问题: Given an array of integers A and let n to be its leng...
    Cloudox_阅读 1,616评论 0 0
  • “心有灵犀一点通”人尽皆知,说归说,其实在和朋友的交往中,反正我从来没有那种特别明显的“心心相通”的感觉,平时只...
    一剪红梅阅读 3,161评论 0 2
  • 你说远方是你的故乡,你会去追逐你的梦想。是的,曾经受过伤,不顾一切为了自己的信仰。 那么我是否会被遗忘,是否已变成...
    默与阅读 1,477评论 0 1
  • 【第一种人】 不孝敬父母,甚至辱骂、打骂父母,此为第一种,畜生不如的人!(不孝型) 【第二种人】 开口向朋友借钱的...
    乱了夏末蓝了海ever阅读 1,220评论 0 0

友情链接更多精彩内容