当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
Transaction rolled back because it has been marked as rollback-only解决
测试开发基础,教你做一个完整功能的Web平台之环境准备
数据库同步工具 DBSync 新增对MongoDB、ES的支持
Unity script visualization about layout code
Shardingsphere sub database and table examples (logical table, real table, binding table, broadcast table, single table)
Opencv installation and environment configuration - vs2017
Vscode 尝试在目标目录创建文件时发生一个错误:拒绝访问【已解决】
Force buckle 1002 Find common characters
Web端自动化测试失败的原因
RationalDMIS2022 高级编程宏程序
随机推荐
VIM命令模式与输入模式切换
Rolling puddle Uni_ App (VIII)
书签整理-程序员常用网站导航
verilog设计抢答器【附源码】
Ping tool ICMP message learning
Go Slice 比较
Multithreaded application (thread pool, singleton mode)
Process control (creation, termination, waiting, program replacement)
Vuthink正确安装过程
Galaxy Kirin desktop operating system installation postgresql13 (source code installation)
Unity websocket client
学习笔记|数据小白使用DataEase制作数据大屏
The eighth training assignment
Graduation season | keep company with youth and look forward to the future together!
创意信息获2家机构调研:GreatDB 数据库已在9地部署
Hash / (understanding, implementation and application)
Web端自动化测试失败的原因
互联网协议
常用sql语句整理:mysql
[untitled]