当前位置:网站首页>Leetcode dynamic planning day 16
Leetcode dynamic planning day 16
2022-07-06 04:49:00 【worldinme】
Realize the idea :
Is very normal , It's no different from yesterday's topic .
Implementation code :
class Solution {
public int minPathSum(int[][] grid) {
int m=grid.length,n=grid[0].length;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(i==0&&j!=0){
grid[0][j]=grid[0][j-1]+grid[0][j];
}else if(j==0&&i!=0){
grid[i][0]=grid[i-1][0]+grid[i][0];
}else if(i!=0&&j!=0){
grid[i][j]=Math.min(grid[i-1][j],grid[i][j-1])+grid[i][j];
}
}
}
return grid[m-1][n-1];
}
}
Realize the idea :
For this question , The explanation of the official explanation is very clear :
After defining the state transition equation , The code of this problem is easy to write .
Implementation code :
class Solution {
public int maximalSquare(char[][] matrix) {
int m=matrix.length,n=matrix[0].length;
int[][] dp=new int[m][n];
int maxSum=0;
for(int i=0;i<m;i++){
for(int j=0;j<n;j++){
if(matrix[i][j]=='0'){
dp[i][j]=0;
}else if(i==0||j==0){
dp[i][j]=1;
}else{
dp[i][j]=Math.min(Math.min(dp[i-1][j-1],dp[i-1][j]),dp[i][j-1])+1;
}
maxSum=Math.max(dp[i][j],maxSum);
}
}
return maxSum*maxSum;
}
}
边栏推荐
- 8. Static file
- The kernel determines whether peripherals are attached to the I2C address
- win10电脑系统里的视频不显示缩略图
- DMA use of stm32
- Excellent PM must experience these three levels of transformation!
- Summary of three log knowledge points of MySQL
- Quick sort
- Delete subsequence < daily question >
- Postman test report
- 2021 RoboCom 世界机器人开发者大赛-本科组(复赛)
猜你喜欢
Sqlserver query results are not displayed in tabular form. How to modify them
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
Selection of slow motion function
English Vocabulary - life scene memory method
View workflow
canal同步mysql数据变化到kafka(centos部署)
SQL injection vulnerability (MSSQL injection)
DMA use of stm32
[detailed steps of FreeRTOS shift value for the first time]
ORM aggregate query and native database operation
随机推荐
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
Weng Kai C language third week 3.1 punch in
Flink kakfa data read and write to Hudi
Nestjs配置文件上传, 配置中间件以及管道的使用
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
行业专网对比公网,优势在哪儿?能满足什么特定要求?
Upload nestjs configuration files, configure the use of middleware and pipelines
ORM aggregate query and native database operation
yolov5 tensorrt加速
Orm-f & Q object
8. Static file
[05-1, 05-02, 05-03] network protocol
Microservice resource address
word封面下划线
web工程导入了mysql驱动jar包却无法加载到驱动的问题
比尔·盖茨晒18岁个人简历,48年前期望年薪1.2万美元
Platformio create libopencm3 + FreeRTOS project
Summary of redis AOF and RDB knowledge points
Postman前置脚本-全局变量和环境变量
优秀PM必须经历这3层蜕变!