Skip to content

Commit f26a453

Browse files
committed
Time: 584 ms (100.00%), Space: 53.7 MB (50.00%) - LeetHub
1 parent 7fc1af2 commit f26a453

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution {
2+
fun getSumAbsoluteDifferences(nums: IntArray): IntArray {
3+
val n = nums.size
4+
val result = IntArray(n)
5+
6+
var sumByCurrent = nums.sum()
7+
8+
for (i in nums.indices) {
9+
result[i] = sumByCurrent + nums[i] * (i * 2 - n)
10+
sumByCurrent -= nums[i] * 2
11+
}
12+
13+
return result
14+
}
15+
}

0 commit comments

Comments
 (0)