Skip to content

Commit fa6cca9

Browse files
refactor 308
1 parent 358e193 commit fa6cca9

File tree

1 file changed

+13
-10
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.fishercoder.solutions;
22

33
/**
4-
* Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
4+
* 308. Range Sum Query 2D - Mutable
5+
*
6+
* Given a 2D matrix matrix,
7+
* find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).
58
69
Range Sum Query 2D
710
The above rectangle (with the red border) is defined by (row1, col1) = (2, 1) and (row2, col2) = (4, 3), which contains sum = 8.
@@ -24,7 +27,7 @@ The above rectangle (with the red border) is defined by (row1, col1) = (2, 1) an
2427
You may assume that row1 ≤ row2 and col1 ≤ col2.
2528
*/
2629
public class _308 {
27-
class Solution {
30+
public static class Solution1 {
2831
public class NumMatrix {
2932
int[][] nums;
3033
int[][] tree;
@@ -63,7 +66,8 @@ public int sumRegion(int row1, int col1, int row2, int col2) {
6366
if (height == 0 || width == 0) {
6467
return 0;
6568
}
66-
return sum(row2 + 1, col2 + 1) + sum(row1, col1) - sum(row1, col2 + 1) - sum(row2 + 1, col1);
69+
return sum(row2 + 1, col2 + 1) + sum(row1, col1) - sum(row1, col2 + 1) - sum(
70+
row2 + 1, col1);
6771
}
6872

6973
private int sum(int row, int col) {
@@ -75,14 +79,13 @@ private int sum(int row, int col) {
7579
}
7680
return sum;
7781
}
78-
7982
}
8083

81-
/**
82-
* Your NumMatrix object will be instantiated and called as such:
83-
* NumMatrix obj = new NumMatrix(matrix);
84-
* obj.update(row,col,val);
85-
* int param_2 = obj.sumRegion(row1,col1,row2,col2);
86-
*/
84+
/**
85+
* Your NumMatrix object will be instantiated and called as such:
86+
* NumMatrix obj = new NumMatrix(matrix);
87+
* obj.update(row,col,val);
88+
* int param_2 = obj.sumRegion(row1,col1,row2,col2);
89+
*/
8790
}
8891
}

0 commit comments

Comments
 (0)