当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢

Codeforces Round #804 (Div. 2)

View workflow

ISP learning (2)

二叉树基本知识和例题

Postman manage test cases

Application of Flody

Postman关联

The most detailed and comprehensive update content and all functions of guitar pro 8.0

Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems

Weng Kai C language third week 3.1 punch in
随机推荐
Platformio create libopencm3 + FreeRTOS project
ETCD数据库源码分析——etcdserver bootstrap初始化存储
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
canal同步mysql数据变化到kafka(centos部署)
力扣(LeetCode)186. 翻转字符串里的单词 II(2022.07.05)
[HBZ sharing] how to locate slow queries in cloud database
8. Static file
How does vs change the project type?
Pagoda configuration mongodb
几种RS485隔离通讯的方案介绍
麦斯克电子IPO被终止:曾拟募资8亿 河南资产是股东
Platformio create libopencm3 + FreeRTOS project
Etcd database source code analysis -- etcdserver bootstrap initialization storage
优秀PM必须经历这3层蜕变!
Visio draws Tai Chi
Luogu deep foundation part 1 Introduction to language Chapter 2 sequential structure programming
树莓派3.5寸屏幕白屏显示连接
The web project imported the MySQL driver jar package but failed to load it into the driver
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
[FreeRTOS interrupt experiment]