1508. Range Sum of Sorted Subarray Sums

Обновлено: 2024-03-12
1 мин
[]

Содержание

LeetCode problem 1508

class Solution:
    def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int:
        arr = []
        for i in range(n):
            s = 0
            for j in range(i, n):
                s += nums[j]
                arr.append(s)
        arr.sort()
        mod = 10**9 + 7
        return sum(arr[left - 1 : right]) % mod