当前位置:网站首页>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;
}
}边栏推荐
- ue5 小知识点 开启lumen的设置
- 你需要知道的 TCP 三次握手
- 也算是學習中的小總結
- DMA use of stm32
- Redis - redis in action - redis actual combat - actual combat Chapter 1 - SMS login function based on redis - redis + token shared session application - with code
- Platformio create libopencm3 + FreeRTOS project
- Selection of slow motion function
- 关于es8316的音频爆破音的解决
- Sqlserver query results are not displayed in tabular form. How to modify them
- Summary of three log knowledge points of MySQL
猜你喜欢

ORM aggregate query and native database operation

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

从0到1建设智能灰度数据体系:以vivo游戏中心为例

【LGR-109】洛谷 5 月月赛 II & Windy Round 6

ETCD数据库源码分析——etcdserver bootstrap初始化存储

RTP GB28181 文件测试工具

Extension of graph theory

11. Intranet penetration and automatic refresh
![[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University](/img/22/ead74bc121a64910ef6ef374cd029b.png)
[Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
![[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity](/img/ac/93a64e59592e3d083a771b993d6884.jpg)
[Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
随机推荐
几种RS485隔离通讯的方案介绍
程序员在互联网行业的地位 | 每日趣闻
Supreme Court, judgment standard of divorce cases
word封面下划线
Application of Flody
SQL injection vulnerability (MSSQL injection)
[HBZ sharing] how to locate slow queries in cloud database
Postman test report
The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
Unity screen coordinates ugui coordinates world coordinates conversion between three coordinate systems
canal同步mysql数据变化到kafka(centos部署)
[NOIP2008 提高组] 笨小猴
集合详解之 Map + 面试题
Quatre méthodes de redis pour dépanner les grandes clés sont nécessaires pour optimiser
也算是學習中的小總結
ue5 小知识点 开启lumen的设置
你需要知道的 TCP 三次握手
Yolov5 tensorrt acceleration
Introduction of several RS485 isolated communication schemes
Microservice resource address