4 lines in Python

  • 2
    class Solution(object):
        def maxRotateFunction(self, nums):
            now, sums, res, n = sum(i * nums[i] for i in range(len(nums))), sum(nums), float('-inf'), len(nums)
            for i in range(n):
                res, now = max(now, res), now + sums - n * nums[n - i - 1]
            return res if res != float('-inf') else 0

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.