Skip to content

Commit 3fea208

Browse files
committed
Runtime: 80 ms (Top 59.69%) | Memory: 74.3 MB (Top 37.60%)
1 parent 66c51dc commit 3fea208

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,59 @@
1+
// Runtime: 80 ms (Top 59.69%) | Memory: 74.3 MB (Top 37.60%)
12
class Solution {
23
public int orderOfLargestPlusSign(int n, int[][] mines) {
3-
// Create the matrix
4+
// Create the matrix
45
int[][] arr = new int[n][n];
56
for(int[] subArray : arr) {
67
Arrays.fill(subArray, 1);
78
}
8-
9+
910
for(int i = 0; i < mines.length; i++) {
1011
arr[mines[i][0]][mines[i][1]] = 0;
1112
}
12-
13-
// Prefix Count DP arrays
13+
14+
// Prefix Count DP arrays
1415
int[][] dpTop = new int[arr.length][arr.length];
1516
int[][] dpLeft = new int[arr.length][arr.length];
1617
int[][] dpRight = new int[arr.length][arr.length];
1718
int[][] dpBottom = new int[arr.length][arr.length];
18-
19-
// Prefix count of 1 cells on top and left directions
19+
20+
// Prefix count of 1 cells on top and left directions
2021
for(int i = 0; i < arr.length; i++) {
2122
for(int j = 0; j < arr.length; j++) {
2223
if(i - 1 >= 0 && arr[i - 1][j] == 1) {
2324
dpTop[i][j] = 1 + dpTop[i - 1][j];
2425
}
25-
26+
2627
if(j - 1 >= 0 && arr[i][j - 1] == 1) {
2728
dpLeft[i][j] = 1 + dpLeft[i][j - 1];
2829
}
2930
}
3031
}
31-
32-
// Prefix count of 1 cells on bottom and right directions
32+
33+
// Prefix count of 1 cells on bottom and right directions
3334
for(int i = arr.length - 1; i >= 0; i--) {
3435
for(int j = arr.length - 1; j >= 0; j--) {
3536
if(i + 1 < arr.length && arr[i + 1][j] == 1) {
3637
dpBottom[i][j] = 1 + dpBottom[i + 1][j];
3738
}
38-
39+
3940
if(j + 1 < arr.length && arr[i][j + 1] == 1) {
4041
dpRight[i][j] = 1 + dpRight[i][j + 1];
4142
}
4243
}
4344
}
44-
45+
4546
int maxPlusSignLength = 0;
4647
for(int i = 0; i < arr.length; i++) {
4748
for(int j = 0; j < arr.length; j++) {
4849
if(arr[i][j] == 0) continue;
49-
50-
// Minimum adjacent 1 cell count from all four directions to ensure symmetry
50+
51+
// Minimum adjacent 1 cell count from all four directions to ensure symmetry
5152
int minAdjacentOnes = Math.min(Math.min(dpTop[i][j], dpBottom[i][j]), Math.min(dpLeft[i][j], dpRight[i][j]));
5253
maxPlusSignLength = Math.max(maxPlusSignLength, minAdjacentOnes + 1);
5354
}
5455
}
55-
56+
5657
return maxPlusSignLength;
5758
}
58-
}
59+
}

0 commit comments

Comments
 (0)