370. Range Addition
Assume you have an array of length n initialized with all 0's and are given k update operations.
Each operation is represented as a triplet: [startIndex, endIndex, inc] which increments each element of subarray A[startIndex ... endIndex] (startIndex and endIndex inclusive) with inc.
Return the modified array after all k operations were executed.
Example:
Explanation:
解题要点:
同理1109,用DP思想,遍历一次先在start index和end index做好标记,以避免重复运算。然后再遍历根据前一次做好的标记依次往后加。
Last updated
Was this helpful?