Skip to content

Commit 8ebdbc2

Browse files
committed
fix cheatsheet/difference_array.md
1 parent 4d74fb9 commit 8ebdbc2

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

doc/cheatsheet/difference_array.md

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -131,36 +131,11 @@ return Arrays.copyOfRange(tmp, 1, n+1);
131131

132132
```java
133133
// java
134-
// LC 370
135-
class Solution {
136-
public int[] getModifiedArray(int length, int[][] updates) {
137-
// nums 初始化为全 0
138-
int[] nums = new int[length];
139-
// 构造差分解法
140-
Difference df = new Difference(nums);
141-
142-
for (int[] update : updates) {
143-
int i = update[0];
144-
int j = update[1];
145-
int val = update[2];
146-
df.increment(i, j, val);
147-
}
148-
149-
return df.result();
150-
}
151-
}
152-
```
153-
154-
### Corporate Flight Bookings
134+
// LC 370
155135

156-
```java
157-
// java
158-
// LC 1109
159136

160137
// V0
161138
// IDEA : DIFFERENCE ARRAY
162-
// LC 1109
163-
// https://github.com/yennanliu/CS_basics/blob/master/leetcode_java/src/main/java/LeetCodeJava/Array/CorporateFlightBookings.java
164139
public static int[] getModifiedArray(int length, int[][] updates) {
165140

166141
int[] tmp = new int[length + 1]; // or new int[length]; both works
@@ -191,6 +166,32 @@ for (int i = 1; i < tmp.length; i++) {
191166
return Arrays.copyOfRange(tmp, 0, length); // return the sub array between 0, lengh index
192167
}
193168

169+
// V1
170+
class Solution {
171+
public int[] getModifiedArray(int length, int[][] updates) {
172+
// nums 初始化为全 0
173+
int[] nums = new int[length];
174+
// 构造差分解法
175+
Difference df = new Difference(nums);
176+
177+
for (int[] update : updates) {
178+
int i = update[0];
179+
int j = update[1];
180+
int val = update[2];
181+
df.increment(i, j, val);
182+
}
183+
184+
return df.result();
185+
}
186+
}
187+
```
188+
189+
### Corporate Flight Bookings
190+
191+
```java
192+
// java
193+
// LC 1109
194+
194195
// V1
195196
class Solution {
196197
public int[] corpFlightBookings(int[][] bookings, int n) {

0 commit comments

Comments
 (0)