Ruby 4 lines


  • 0
    L
    def get_modified_array(length, updates)
        ret = Array.new(length + 1, 0)
        updates.each {|u| ret[u[0]], ret[u[1] + 1] = ret[u[0]] + u[2], ret[u[1] + 1] - u[2] }
        count = 0
        return ret.map!{|x| x = (count += x) }[0...-1]
    end
    

Log in to reply
 

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