LeetCode 370 Range Addition

LeetCode 370 Range Addition Problem

Download Code
class Solution(object):
    def getModifiedArray(self, length, updates):
        :type length: int
        :type updates: List[List[int]]
        :rtype: List[int]
        res = [0] * length
        # interval problem
        for t in updates:
            start, end, val = t
            res[start] += val
            if end < length - 1:
                res[end + 1] -= val
        # Cumulative sums
        for i in range(1, length):
            res[i] = res[i] + res[i - 1]
        return res
Download Range Addition.py

List of all Range Addition problems

Leetcode 370 Range Addition problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.

Feedback is the most important part of any website.

If you have any query, suggestion or feedback, Please feel free to contact us.