当前位置:网站首页>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;
}
}
边栏推荐
- 通过 Play Integrity API 的 nonce 字段提高应用安全性
- Table replication in PostgreSQL
- Qtcreator sets multiple qmake
- Using ENSP to do MPLS pseudo wire test
- TDengine 社区问题双周精选 | 第二期
- Vuthink正确安装过程
- Transaction rolled back because it has been marked as rollback-only解决
- About the application of writing shell script JSON in JMeter
- How to play video on unityui
- 关于jmeter中编写shell脚本json的应用
猜你喜欢
随机推荐
Input type= "password" how to solve the problem of password automatically brought in
2021 summary and 2022 outlook
mif 文件格式记录
When initializing 'float', what is the difference between converting to 'float' and adding 'f' as a suffix?
Arduino receives and sends strings
Drive HC based on de2115 development board_ SR04 ultrasonic ranging module [source code attached]
Transaction rolled back because it has been marked as rollback-only解决
[untitled]
数据库同步工具 DBSync 新增对MongoDB、ES的支持
基于DE2 115开发板驱动HC_SR04超声波测距模块【附源码】
2021 summary and 2022 outlook
After the uniapp jumps to the page in onlaunch, click the event failure solution
Opencv installation and environment configuration - vs2017
The eighth training assignment
About the application of writing shell script JSON in JMeter
Web端自动化测试失败的原因
從色情直播到直播電商
Go-Redis 中间件
[untitled]
Network foundation (1)