1class Solution {2public int[] getSumAbsoluteDifferences(int[] nums) {3int n = nums.length;4int[] res = new int[n];5int sumBelow = 0;6int sumTotal = Arrays.stream(nums).sum();78for (int i = 0; i < n; i++) {9int num = nums[i];10sumTotal -= num;11res[i] = sumTotal - (n - i - 1) * num + i * num - sumBelow;12sumBelow += num;13}14return res;15}16}