forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_1508.java
27 lines (25 loc) · 811 Bytes
/
_1508.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.fishercoder.solutions;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class _1508 {
public static class Solution1 {
public int rangeSum(int[] nums, int n, int left, int right) {
List<Long> list = new ArrayList<>();
for (int i = 0; i < nums.length; i++) {
long sum = nums[i];
list.add(sum);
for (int j = i + 1; j < nums.length; j++) {
sum += nums[j];
list.add(sum);
}
}
Collections.sort(list);
long result = 0;
for (int i = left - 1; i < right; i++) {
result += list.get(i);
}
return (int) result % 1000000007;
}
}
}