File tree Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Expand file tree Collapse file tree 1 file changed +7
-8
lines changed Original file line number Diff line number Diff line change @@ -4,19 +4,18 @@ public int maximalSquare(char[][] matrix) {
4
4
return 0 ;
5
5
}
6
6
7
- int m = matrix .length , n = matrix [0 ].length ;
8
- int [][] dp = new int [m + 1 ][n + 1 ];
9
- int result = 0 ;
7
+ int maxSquareLen = 0 ;
8
+ int [][] dp = new int [matrix .length + 1 ][matrix [0 ].length + 1 ];
10
9
11
- for (int i = 1 ; i <= m ; i ++) {
12
- for (int j = 1 ; j <= n ; j ++) {
10
+ for (int i = 1 ; i <= matrix . length ; i ++) {
11
+ for (int j = 1 ; j <= matrix [ 0 ]. length ; j ++) {
13
12
if (matrix [i - 1 ][j - 1 ] == '1' ) {
14
- dp [i ][j ] = Math .min (dp [i - 1 ][j - 1 ], Math . min ( dp [i - 1 ][j ], dp [i ][j - 1 ])) + 1 ;
15
- result = Math .max (result , dp [i ][j ]);
13
+ dp [i ][j ] = 1 + Math .min (Math . min ( dp [i ][j - 1 ], dp [i - 1 ][j ]) , dp [i - 1 ][j - 1 ]);
14
+ maxSquareLen = Math .max (maxSquareLen , dp [i ][j ]);
16
15
}
17
16
}
18
17
}
19
18
20
- return result * result ;
19
+ return maxSquareLen * maxSquareLen ;
21
20
}
22
21
}
You can’t perform that action at this time.
0 commit comments