7 line concise python answer


  • 0
    S
    class Solution(object):
        def getModifiedArray(self, length, updates):
            """
            :type length: int
            :type updates: List[List[int]]
            :rtype: List[int]
            """
            base = [0]*(length+2)
            
            for up in updates:
                base[up[0]+1] += up[2]
                base[up[1]+2] -= up[2]
                
            for i in xrange(1,length+1):
                base[i] += base[i-1]
            
            return base[1:length+1]
    

Log in to reply
 

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