1685. Sum of Absolute Differences in a Sorted Array
Содержание
class Solution:
def getSumAbsoluteDifferences(self, nums: List[int]) -> List[int]:
res = []
s, t = sum(nums), 0
for i, x in enumerate(nums):
v = x * i - t + s - t - x * (len(nums) - i)
res.append(v)
t += x
return res