当前位置:网站首页>LeetCode - 面试题17.24 最大子矩阵
LeetCode - 面试题17.24 最大子矩阵
2022-07-07 09:17:00 【三岁就很萌@D】
动态规划
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;
}
}
边栏推荐
- The opacity value becomes 1%
- Array object sorting
- [untitled]
- The concept, implementation and analysis of binary search tree (BST)
- Ping tool ICMP message learning
- QT document
- When initializing 'float', what is the difference between converting to 'float' and adding 'f' as a suffix?
- 科普达人丨一文弄懂什么是云计算?
- 使用引用
- Unity websocket server
猜你喜欢
Force buckle 1002 Find common characters
解决VSCode只能开两个标签页的问题
Shardingsphere sub database and table examples (logical table, real table, binding table, broadcast table, single table)
Still cannot find RPC dispatcher table failed to connect in virtual KD
shardingsphere分库分表示例(逻辑表,真实表,绑定表,广播表,单表)
【pyqt】tableWidget里的cellWidget使用信号与槽机制
基于华为云IOT设计智能称重系统(STM32)
Antd select selector drop-down box follows the scroll bar to scroll through the solution
Drive HC based on de2115 development board_ SR04 ultrasonic ranging module [source code attached]
【C#】WinForm运行缩放(变糊)的解决方法
随机推荐
Ffmpeg record a video command from RTSP
A simple example of delegate usage
The concept, implementation and analysis of binary search tree (BST)
变量的解构赋值
Eth trunk link switching delay is too high
测试开发基础,教你做一个完整功能的Web平台之环境准备
Graduation season | keep company with youth and look forward to the future together!
2022.7.4DAY596
[untitled]
关于jmeter中编写shell脚本json的应用
Laya common script commands
seata 1.3.0 四種模式解决分布式事務(AT、TCC、SAGA、XA)
常用sql语句整理:mysql
Mysql的json格式查询
Go Slice 比较
创意信息获2家机构调研:GreatDB 数据库已在9地部署
MPX plug-in
Cmake learning manual
How to use cherry pick?
Go redis Middleware