Loading...
Loading...
You are given a list of integers nums and a list of operations operations.
Each element in operations contains [l, r, x] meaning increment every element of nums from index l to index r, inclusive, by x. Note that x can be negative, which decrements that range instead.
Apply every operation to nums in the order given.
Return nums after all operations have been applied.
Input: nums = [0, 0, 0, 0, 0]
operations = [[1, 3, 2],
[2, 4, 3],
[0, 2, -2]]
Output: [-2, 0, 3, 5, 3]
Explanation: [1,3,2] adds 2 to indices 1 through 3, giving [0,2,2,2,0].
[2,4,3] adds 3 to indices 2 through 4, giving [0,2,5,5,3].
[0,2,-2] subtracts 2 from indices 0 through 2, giving [-2,0,3,5,3].
Input: nums = [1, 2, 3]
operations = [[0, 1, 5],
[1, 2, -3]]
Output: [6, 4, 0]
Explanation: [0,1,5] adds 5 to indices 0 through 1, giving [6,7,3].
[1,2,-3] subtracts 3 from indices 1 through 2, giving [6,4,0].
nums.length ≤104operations.length ≤104operations[i].length =3l ≤ r < nums.lengthx ≤105nums[i] ≤106