当前位置:网站首页>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;
}
}边栏推荐
- Lepton 无损压缩原理及性能分析
- 2021 robocom world robot developer competition - undergraduate group (semi-finals)
- I'd like to ask about the current MySQL CDC design. In the full volume phase, if a chunk's binlog backfill phase,
- [Yu Yue education] reference materials of complex variable function and integral transformation of Northwestern Polytechnic University
- Postman测试报告
- Acwing week 58
- Postman Association
- The IPO of mesk Electronics was terminated: Henan assets, which was once intended to raise 800 million yuan, was a shareholder
- Basic explanation of turtle module - draw curve
- Dry goods collection | Vulkan game engine video tutorial
猜你喜欢

Postman断言

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

IPv6 comprehensive experiment

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

Use sentinel to interface locally

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

The underlying structure of five data types in redis

acwing周赛58

Dry goods collection | Vulkan game engine video tutorial

ETCD数据库源码分析——etcdserver bootstrap初始化存储
随机推荐
Codeforces Round #804 (Div. 2)
Introduction of several RS485 isolated communication schemes
2021robocom robot developer competition (Preliminary)
Delete subsequence < daily question >
It is also a small summary in learning
Weng Kai C language third week 3.1 punch in
L'introduction en bourse de MSK Electronics a pris fin: 800 millions de RMB d'actifs de Henan étaient des actionnaires
Biscuits (examination version)
Zynq learning notes (3) - partial reconfiguration
Yyds dry goods inventory OSI & tcp/ip
Bubble sort
Database - MySQL storage engine (deadlock)
Selection sort
Yolov5 tensorrt acceleration
行业专网对比公网,优势在哪儿?能满足什么特定要求?
IPv6 comprehensive experiment
English Vocabulary - life scene memory method
win10电脑系统里的视频不显示缩略图
Scala function advanced
2021RoboCom机器人开发者大赛(初赛)