结果应该是:
但我的测试结果是:
代码如下:
class Solution {
public int rampartDefensiveLine(int[][] rampart) {
int maxLen = 0;
int n = rampart.length;
int m = rampart[0].length;
int[][] dp = new int[n][m];
for (int j = 0; j < m; j++) {
for (int i = n - 1; i >= 0; i--) {
if (rampart[i][j] == 0) {
dp[i][j] = 0;
} else {
dp[i][j] = i == n - 1 ? 1 : dp[i + 1][j] + 1;
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int len = dp[i][j];
for (int k = j + 1; k < m && dp[i][k] > 0; k++) {
if (dp[i][k] < len) {
len = dp[i][k];
}
maxLen = Math.max(maxLen, (k - j + 1) * len);
}
}
}
return maxLen;
}
}
请问我的代码哪里需要做修改呢?或是新的思路也可以,需要代码java代码谢谢