当前位置:网站首页>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;
}
}
边栏推荐
- Seata 1.3.0 four modes to solve distributed transactions (at, TCC, Saga, XA)
- 关于测试人生的一站式发展建议
- Realize ray detection, drag the mouse to move the object and use the pulley to scale the object
- 2021-04-23
- Project ERROR: Unknown module(s) in QT: core gui
- Transaction rolled back because it has been marked as rollback only
- Input type= "password" how to solve the problem of password automatically brought in
- RationalDMIS2022阵列工件测量
- Arduino board description
- Arduino receives and sends strings
猜你喜欢

Basic knowledge of process (orphan, zombie process)

What if copying is prohibited?

Force buckle 1002 Find common characters

Opencv installation and environment configuration - vs2017

解决VSCode只能开两个标签页的问题

2021-04-08

关于在云服务器上(这里用腾讯云)安装mysql8.0并使本地可以远程连接的方法
![[untitled]](/img/a0/29975bc0f9832e1640cc39dfce4a71.jpg)
[untitled]

From pornographic live broadcast to live broadcast E-commerce

关于SIoU《SIoU Loss: More Powerful Learning for Bounding Box Regression Zhora Gevorgyan 》的一些看法及代码实现
随机推荐
Using ENSP to do MPLS pseudo wire test
0.96 inch IIC LCD driver based on stc8g1k08
Kitex 重试机制
Laya common script commands
VIM命令模式与输入模式切换
Go Slice 比较
解决VSCode只能开两个标签页的问题
The concept, implementation and analysis of binary search tree (BST)
uniapp 在onLaunch中跳转页面后,点击事件失效解决方法
uniCloud
Mpx 插件
互联网协议
Debezium同步之Debezium架构详解
简单介绍一下闭包及它的一些应用场景
Go-Redis 中间件
毕业季|与青春作伴,一起向未来!
How to remove addition and subtraction from inputnumber input box
2021-04-08
基于DE2 115开发板驱动HC_SR04超声波测距模块【附源码】
How to play video on unityui