当前位置:网站首页>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;
}
}边栏推荐
- Pagoda configuration mongodb
- Coreldraw2022 new version new function introduction cdr2022
- ue5 小知识点 开启lumen的设置
- Dynamic programming (tree DP)
- The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
- Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
- [noip2009 popularization group] score line delimitation
- Excellent PM must experience these three levels of transformation!
- 集合详解之 Collection + 面试题
- Postman前置脚本-全局变量和环境变量
猜你喜欢

IPv6 comprehensive experiment

Canal synchronizes MySQL data changes to Kafka (CentOS deployment)

The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder

Flink kakfa data read and write to Hudi
![[classic example] binary tree recursive structure classic topic collection @ binary tree](/img/39/0319c4be43716f927b9d98d89f7655.jpg)
[classic example] binary tree recursive structure classic topic collection @ binary tree

Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code

Postman pre script - global variables and environment variables
![[05-1, 05-02, 05-03] network protocol](/img/25/2e9ccc3f31a1fd46c9ab643d48064b.jpg)
[05-1, 05-02, 05-03] network protocol

Etcd database source code analysis -- etcdserver bootstrap initialization storage

Postman断言
随机推荐
Canal synchronizes MySQL data changes to Kafka (CentOS deployment)
Scala function advanced
Why does MySQL need two-phase commit
Bill Gates posted his 18-year-old resume and expected an annual salary of $12000 48 years ago
The video in win10 computer system does not display thumbnails
饼干(考试版)
Distributed transaction solution
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
MIT CMS. 300 session 8 – immersion / immersion
SQL injection vulnerability (MSSQL injection)
[NOIP2009 普及组] 分数线划定
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
Sqlserver query results are not displayed in tabular form. How to modify them
Lagrange polynomial
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
Delete subsequence < daily question >
I'd like to ask about the current MySQL CDC design. In the full volume phase, if a chunk's binlog backfill phase,
[classic example] binary tree recursive structure classic topic collection @ binary tree
Flody的应用
Zynq learning notes (3) - partial reconfiguration