Skip to content

Commit 31c410b

Browse files
authored
Create Solution.java
1 parent 00b93c5 commit 31c410b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int sumSubseqWidths(int[] A) {
3+
final int MOD = (int) (1e9 + 7);
4+
Arrays.sort(A);
5+
int n = A.length;
6+
long res = 0;
7+
long p = 1;
8+
for (int i = 0; i < n; ++i) {
9+
res = (res + (A[i] - A[n - 1 - i]) * p) % MOD;
10+
p = (p << 1) % MOD;
11+
}
12+
return (int) ((res + MOD) % MOD);
13+
}
14+
}

0 commit comments

Comments
 (0)