Skip to content

Commit e100cbd

Browse files
committed
modify code
1 parent b8a091b commit e100cbd

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

src/class048/Code01_PrefixSumMatrix.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public NumMatrix(int[][] matrix) {
2424
}
2525
}
2626

27-
public int sumRegion(int row1, int col1, int row2, int col2) {
28-
row2++;
29-
col2++;
30-
return sum[row2][col2] - sum[row2][col1] - sum[row1][col2] + sum[row1][col1];
27+
public int sumRegion(int a, int b, int c, int d) {
28+
c++;
29+
d++;
30+
return sum[c][d] - sum[c][b] - sum[a][d] + sum[a][b];
3131
}
3232

3333
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
import java.io.PrintWriter;
1414
import java.io.StreamTokenizer;
1515

16-
public class Code04_DiffMatrixLuogu {
16+
public class Code03_DiffMatrixLuogu {
1717

1818
public static int MAXN = 1002;
1919

2020
public static int[][] diff = new int[MAXN][MAXN];
2121

2222
public static int n, q;
2323

24-
public static void set(int a, int b, int c, int d, int k) {
24+
public static void add(int a, int b, int c, int d, int k) {
2525
diff[a][b] += k;
2626
diff[c + 1][b] -= k;
2727
diff[a][d + 1] -= k;
@@ -61,7 +61,7 @@ public static void main(String[] args) throws IOException {
6161
c = (int) in.nval;
6262
in.nextToken();
6363
d = (int) in.nval;
64-
set(a, b, c, d, 1);
64+
add(a, b, c, d, 1);
6565
}
6666
build();
6767
for (int i = 1; i <= n; i++) {

src/class048/Code03_DiffMatrixNowcoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Code03_DiffMatrixNowcoder {
2323

2424
public static int n, m, q;
2525

26-
public static void set(int a, int b, int c, int d, int k) {
26+
public static void add(int a, int b, int c, int d, int k) {
2727
diff[a][b] += k;
2828
diff[c + 1][b] -= k;
2929
diff[a][d + 1] -= k;
@@ -59,7 +59,7 @@ public static void main(String[] args) throws IOException {
5959
for (int i = 1; i <= n; i++) {
6060
for (int j = 1; j <= m; j++) {
6161
in.nextToken();
62-
set(i, j, i, j, (int) in.nval);
62+
add(i, j, i, j, (int) in.nval);
6363
}
6464
}
6565
for (int i = 1, a, b, c, d, k; i <= q; i++) {
@@ -73,7 +73,7 @@ public static void main(String[] args) throws IOException {
7373
d = (int) in.nval;
7474
in.nextToken();
7575
k = (int) in.nval;
76-
set(a, b, c, d, k);
76+
add(a, b, c, d, k);
7777
}
7878
build();
7979
for (int i = 1; i <= n; i++) {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// 邮票不允许旋转,邮票必须完全在矩阵内
1111
// 如果在满足上述要求的前提下,可以放入邮票,请返回 true ,否则返回 false
1212
// 测试链接 : https://leetcode.cn/problems/stamping-the-grid/
13-
public class Code05_StampingTheGrid {
13+
public class Code04_StampingTheGrid {
1414

1515
public static boolean possibleToStamp(int[][] grid, int h, int w) {
1616
int n = grid.length;
@@ -32,7 +32,7 @@ public static boolean possibleToStamp(int[][] grid, int h, int w) {
3232
for (int b = 1, d = b + w - 1; d <= m; b++, d++) {
3333
// (a,b) (c,d)
3434
if (empty(sum, a, b, c, d)) {
35-
set(diff, a, b, c, d);
35+
add(diff, a, b, c, d);
3636
}
3737
}
3838
}
@@ -60,7 +60,7 @@ public static boolean empty(int[][] sum, int a, int b, int c, int d) {
6060
return sum[c][d] - sum[c][b - 1] - sum[a - 1][d] + sum[a - 1][b - 1] == 0;
6161
}
6262

63-
public static void set(int[][] diff, int a, int b, int c, int d) {
63+
public static void add(int[][] diff, int a, int b, int c, int d) {
6464
diff[a][b] += 1;
6565
diff[c + 1][d + 1] += 1;
6666
diff[c + 1][b] -= 1;

src/class048/Code06_StrongestForceField.java renamed to src/class048/Code05_StrongestForceField.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// 请求出在这片地带中 力场强度 最强处的 力场强度
1313
// 注意:力场范围的边缘同样被力场覆盖。
1414
// 测试链接 : https://leetcode.cn/problems/xepqZ5/
15-
public class Code06_StrongestForceField {
15+
public class Code05_StrongestForceField {
1616

1717
public static int fieldOfGreatestBlessing(int[][] fields) {
1818
int n = fields.length;
@@ -39,7 +39,7 @@ public static int fieldOfGreatestBlessing(int[][] fields) {
3939
b = rank(ys, (y << 1) - r, sizey);
4040
c = rank(xs, (x << 1) + r, sizex);
4141
d = rank(ys, (y << 1) + r, sizey);
42-
set(diff, a, b, c, d);
42+
add(diff, a, b, c, d);
4343
}
4444
int ans = 0;
4545
for (int i = 1; i < diff.length; i++) {
@@ -79,7 +79,7 @@ public static int rank(long[] nums, long v, int size) {
7979
}
8080

8181
// 二维差分
82-
public static void set(int[][] diff, int a, int b, int c, int d) {
82+
public static void add(int[][] diff, int a, int b, int c, int d) {
8383
diff[a][b] += 1;
8484
diff[c + 1][d + 1] += 1;
8585
diff[c + 1][b] -= 1;

0 commit comments

Comments
 (0)