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.
Examples
Example 1
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].
Example 2
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].
Constraints
1≤nums.length≤104
0≤operations.length≤104
operations[i].length=3
0≤l≤r<nums.length
−105≤x≤105
−106≤nums[i]≤106
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 2
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run