当前位置:网站首页>Leetcode - interview question 17.24 maximum submatrix
Leetcode - interview question 17.24 maximum submatrix
2022-07-07 11:16:00 【Cute at the age of three @d】
Dynamic programming
class Solution {
public int[] getMaxMatrix(int[][] matrix) {
int m = matrix.length;
int n = matrix[0].length;
int[] sum = new int[n];
int[] ans = new int[4];
int last = 0;
int maxval = matrix[0][0];
int begin = 0;
for(int i = 0; i <m;i++){
Arrays.fill(sum,0);
for(int j = i; j < m;j++){
sum[0] += matrix[j][0];
last = sum[0];
begin = 0;
for(int k = 1; k < n;k++){
sum[k] += matrix[j][k];
if(last > 0){
last += sum[k];
}
else{
last = sum[k];
begin = k;
}
if(last > maxval){
maxval = last;
ans[0] = i;
ans[1] = begin;
ans[2] = j;
ans[3] = k;
}
}
}
}
return ans;
}
}
边栏推荐
猜你喜欢
Mpx 插件
Vscode 尝试在目标目录创建文件时发生一个错误:拒绝访问【已解决】
关于SIoU《SIoU Loss: More Powerful Learning for Bounding Box Regression Zhora Gevorgyan 》的一些看法及代码实现
Array object sorting
seata 1.3.0 四種模式解决分布式事務(AT、TCC、SAGA、XA)
测试优惠券要怎么写测试用例?
[C #] the solution of WinForm operation zoom (blur)
[untitled]
PostgreSQL中的表复制
Activity lifecycle
随机推荐
mif 文件格式记录
The opacity value becomes 1%
The database synchronization tool dbsync adds support for mongodb and es
【时间格式工具函数的封装】
Go-Redis 中间件
Opencv installation and environment configuration - vs2017
JS array delete the specified element
【pyqt】tableWidget里的cellWidget使用信号与槽机制
Introduction to shell programming
electron添加SQLite数据库
Vscode 尝试在目标目录创建文件时发生一个错误:拒绝访问【已解决】
测试开发基础,教你做一个完整功能的Web平台之环境准备
The concept, implementation and analysis of binary search tree (BST)
Galaxy Kirin desktop operating system installation postgresql13 (source code installation)
数据库同步工具 DBSync 新增对MongoDB、ES的支持
JS add spaces to the string
测试优惠券要怎么写测试用例?
oracle常见锁表处理方式
從色情直播到直播電商
Rolling puddle Uni_ App (VIII)