Skip to content

Commit 9f6a970

Browse files
committed
Runtime: 88 ms (Top 26.15%) | Memory: 43.2 MB (Top 92.07%)
1 parent c1fbc98 commit 9f6a970

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

scripts/algorithms/M/Matrix Block Sum/Matrix Block Sum.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
// Runtime: 88 ms (Top 26.15%) | Memory: 43.2 MB (Top 92.07%)
12
class Solution {
23
public int[][] matrixBlockSum(int[][] mat, int k) {
34
int m = mat.length,n = mat[0].length;
45
int[][] answer = new int[m][n];
56
for(int i=0;i<m;i++){
67
for(int j=0;j<n;j++){
78
int val = 0;
8-
// take new variables to get starting index of mat[r][c]
9+
// take new variables to get starting index of mat[r][c]
910
int p = i-k,q=j-k;
10-
//make sure p and q are atleast 0 (i.e. valid)
11+
//make sure p and q are atleast 0 (i.e. valid)
1112
while(p<0)
1213
p++;
1314
while(q<0)
1415
q++;
15-
//traverse again in the matrix with starting at p,q and ending at i+k and j+k
16-
//add conditions to make sure the indices dont cross the values of m and n
16+
//traverse again in the matrix with starting at p,q and ending at i+k and j+k
17+
//add conditions to make sure the indices dont cross the values of m and n
1718
for(int x = p;x<=i+k && x<m;x++){
1819
for(int y = q;y<=j+k && y<n;y++){
1920
val += mat[x][y];

0 commit comments

Comments
 (0)