当前位置:网站首页>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;
}
}
边栏推荐
- 从色情直播到直播电商
- Verilog design responder [with source code]
- PostgreSQL中的表复制
- [untitled]
- 测试优惠券要怎么写测试用例?
- The fifth training assignment
- The seventh training assignment
- Go redis Middleware
- Activity生命周期
- Shardingsphere sub database and table examples (logical table, real table, binding table, broadcast table, single table)
猜你喜欢

从色情直播到直播电商

The concept, implementation and analysis of binary search tree (BST)

技术分享 | 抓包分析 TCP 协议
![[pyqt] the cellwidget in tablewidget uses signal and slot mechanism](/img/0e/02265f7195ca0add4155694530822a.png)
[pyqt] the cellwidget in tablewidget uses signal and slot mechanism

JS add spaces to the string

Ping tool ICMP message learning
![Verilog realizes nixie tube display driver [with source code]](/img/ad/be94912bedc738f4b5f97138db7352.png)
Verilog realizes nixie tube display driver [with source code]

Antd select selector drop-down box follows the scroll bar to scroll through the solution

electron添加SQLite数据库

RationalDMIS2022阵列工件测量
随机推荐
Rolling puddle Uni_ App (VIII)
Which securities company is the best and safest to open an account for the subscription of new shares
Wallhaven壁纸桌面版
Shardingsphere sub database and table examples (logical table, real table, binding table, broadcast table, single table)
When initializing 'float', what is the difference between converting to 'float' and adding 'f' as a suffix?
oracle常见锁表处理方式
VIM命令模式与输入模式切换
Template initial level template
IDEA快捷键大全
Web端自动化测试失败的原因
通过 Play Integrity API 的 nonce 字段提高应用安全性
毕业季|与青春作伴,一起向未来!
Case study of Jinshan API translation function based on retrofit framework
The eighth training assignment
2021-05-21
About the application of writing shell script JSON in JMeter
uniCloud
[pyqt] the cellwidget in tablewidget uses signal and slot mechanism
Arduino receives and sends strings
The use of list and Its Simulation Implementation