当前位置:网站首页>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;
}
}
边栏推荐
- Visio draw fan
- Acwing week 58
- Microservice resource address
- On the solution of es8316's audio burst
- Request (request object) and response (response object)
- Sqlserver query results are not displayed in tabular form. How to modify them
- Redis has four methods for checking big keys, which are necessary for optimization
- Redis 排查大 key 的4種方法,優化必備
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- ue5 小知识 FreezeRendering 查看视锥内渲染的物体
猜你喜欢
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
Use sentinel to interface locally
Uva1592 Database
canal同步mysql数据变化到kafka(centos部署)
Crazy God said redis notes
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
The underlying structure of five data types in redis
View workflow
Visio draw fan
[classic example] binary tree recursive structure classic topic collection @ binary tree
随机推荐
Weng Kai C language third week 3.1 punch in
饼干(考试版)
[mathematical modeling] differential equation -- sustainable development of fishing industry
Visio draws Tai Chi
Postman关联
项目经理,你会画原型嘛?项目经理需要做产品设计了?
Postman断言
SharedPreferences source code analysis
Pagoda configuration mongodb
[detailed steps of FreeRTOS shift value for the first time]
Easyrecovery reliable and toll free data recovery computer software
Complete list of common functions of turtle module
Codeforces Round #804 (Div. 2)
win10电脑系统里的视频不显示缩略图
A blog to achieve embedded entry
Database - MySQL storage engine (deadlock)
ue5 小知识 FreezeRendering 查看视锥内渲染的物体
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
最高法院,离婚案件判决标准
Application of Flody