Skip to content

Commit c364b32

Browse files
refactor 370
1 parent 2ce1c6e commit c364b32

File tree

1 file changed

+0
-43
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+0
-43
lines changed

src/main/java/com/fishercoder/solutions/_370.java

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,5 @@
11
package com.fishercoder.solutions;
22

3-
/**
4-
* 370. Range Addition
5-
*
6-
* Assume you have an array of length n initialized with all 0's and are given k update operations.
7-
* Each operation is represented as a triplet: [startIndex, endIndex, inc]
8-
* which increments each element of subarray A[startIndex ... endIndex] (startIndex and endIndex inclusive) with inc.
9-
* Return the modified array after all k operations were executed.
10-
11-
Example:
12-
13-
Given:
14-
15-
length = 5,
16-
updates = [
17-
[1, 3, 2],
18-
[2, 4, 3],
19-
[0, 2, -2]
20-
]
21-
22-
Output:
23-
24-
[-2, 0, 3, 5, 3]
25-
Explanation:
26-
27-
Initial state:
28-
[ 0, 0, 0, 0, 0 ]
29-
30-
After applying operation [1, 3, 2]:
31-
[ 0, 2, 2, 2, 0 ]
32-
33-
After applying operation [2, 4, 3]:
34-
[ 0, 2, 5, 5, 3 ]
35-
36-
After applying operation [0, 2, -2]:
37-
[-2, 0, 3, 5, 3 ]
38-
39-
Hint:
40-
Thinking of using advanced data structures? You are thinking it too complicated.
41-
For each update operation, do you really need to update all elements between i and j?
42-
Update only the first and end element is sufficient.
43-
The optimal time complexity is O(k + n) and uses O(1) extra space.
44-
*/
45-
463
public class _370 {
474
public static class Solution1 {
485
public int[] getModifiedArray(int length, int[][] updates) {

0 commit comments

Comments
 (0)