Python solution


  • 0
    F
    class Solution(object):
        def getModifiedArray(self, length, updates):
            """
            :type length: int
            :type updates: List[List[int]]
            :rtype: List[int]
            """
            result = [0] * length 
            
            for update in updates:
                result[update[0]] = result[update[0]] + update[2]
                if update[1] + 1 < length:
                    result[update[1]+1] = result[update[1]+1] - update[2]
    
            curr = 0
            for i in xrange(0,length):
                curr = curr + result[i]
                result[i] = curr 
            
            return result
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.