Python O(n+k)


  • 0
    O

    Loops can probably be done more cleanly:

        def getModifiedArray(self, length, updates):
            ret = [0]*(length+1)
            for u in updates:
                ret[u[0]] = u[2]+ ret[u[0]]
                ret[u[1]+1] = -u[2] + ret[u[1]+1]
            for i in range(1,len(ret)):
                ret[i]=ret[i-1]+ret[i]
            return ret[0:length]
    

Log in to reply
 

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