Java Solution | Beats 100%
Runtime: 2 ms, faster than 100.00% of Java online submissions for Sum of Absolute Differences in a Sorted Array.\nMemory Usage: 54.3 MB, less than 47% of Java o
Runtime: 2 ms, faster than 100.00% of Java online submissions for Sum of Absolute Differences in a Sorted Array.\nMemory Usage: 54.3 MB, less than 47% of Java online submissions for Sum of Absolute Differences in a Sorted Array.\n\n```\nclass Solution {\n    public int[] getSumAbsoluteDifferences(int[] nums) {\n        int right = 0;\n        int left = 0;\n        int[] result = new int[nums.length];\n        int n = nums.length;\n        for(int i = 0 ; i < n ; i++) right +=nums[i];\n        for(int i = 0 ; i < n ; i++){\n            right -= nums[i];\n            result[i] = right - left - (n - 2*i - 1)*nums[i];\n            left += nums[i];\n        }\n        return result;\n    }\n}\n```
['Java']