当前位置:网站首页>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;
}
}
边栏推荐
- Weng Kai C language third week 3.1 punch in
- Codeforces Round #804 (Div. 2)
- 饼干(考试版)
- 2021 robocom world robot developer competition - undergraduate group (semi-finals)
- Dry goods collection | Vulkan game engine video tutorial
- Postman assertion
- Finance online homework
- 11. Intranet penetration and automatic refresh
- acwing周赛58
- View workflow
猜你喜欢
Dry goods collection | Vulkan game engine video tutorial
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
Flody的应用
Fuzzy -- basic application method of AFL
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
Yolov5 tensorrt acceleration
Is the mode of education together - on campus + off campus reliable
几种RS485隔离通讯的方案介绍
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
Weng Kai C language third week 3.1 punch in
随机推荐
11. Intranet penetration and automatic refresh
Selection sort
Request (request object) and response (response object)
[mathematical modeling] differential equation -- sustainable development of fishing industry
The underlying structure of five data types in redis
Weng Kai C language third week 3.1 punch in
[try to hack] John hash cracking tool
A blog to achieve embedded entry
ORM aggregate query and native database operation
最高法院,离婚案件判决标准
【Try to Hack】john哈希破解工具
Summary of three log knowledge points of MySQL
Upload nestjs configuration files, configure the use of middleware and pipelines
[buuctf.reverse] 159_ [watevrCTF 2019]Watshell
[HBZ sharing] how to locate slow queries in cloud database
Platformio create libopencm3 + FreeRTOS project
2021robocom robot developer competition (Preliminary)
Postman pre script - global variables and environment variables
Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
你需要知道的 TCP 三次握手