当前位置:网站首页>Sword finger offer II 099 Sum of minimum paths - double hundred code
Sword finger offer II 099 Sum of minimum paths - double hundred code
2022-07-02 23:04:00 【Mr Gao】
The finger of the sword Offer II 099. Sum of minimum paths
Given a... That contains a nonnegative integer m x n grid grid , Please find a path from the top left corner to the bottom right corner , Make the sum of the numbers on the path the smallest .
explain : A robot can only move down or right one step at a time .
Example 1:
Input :grid = [[1,3,1],[1,5,1],[4,2,1]]
Output :7
explain : Because the path 1→3→1→1→1 The sum of is the smallest .
Example 2:
Input :grid = [[1,2,3],[4,5,6]]
Output :12
The key to solving this problem is to know , Each point is obtained from the upper point or the left point
The solution code is as follows :
int minPathSum(int** grid, int gridSize, int* gridColSize){
int i,j;
int n=gridSize,m=gridColSize[0];
// printf("nm %d %d || ",n,m);
int k=fmin(m,n);
for(i=0;i<k;i++){
for(j=i;j<m;j++){
// printf("%d %d ",i,j);
if(j==0&&i==0){
continue;
}
if(i==0){
grid[i][j]=grid[i][j-1]+ grid[i][j];
}
else{
if(grid[i][j-1]<grid[i-1][j]){
grid[i][j]=grid[i][j]+grid[i][j-1];
}
else{
grid[i][j]=grid[i][j]+grid[i-1][j];
}
}
// printf("%d %d %d ",i,j,grid[i][j]);
}
for(j=i+1;j<n;j++){
if(i==0){
grid[j][i]=grid[j-1][i]+ grid[j][i];
}
else{
if(grid[j][i-1]<grid[j-1][i]){
grid[j][i]=grid[j][i]+grid[j][i-1];
}
else{
grid[j][i]=grid[j][i]+grid[j-1][i];
}
}
// printf("-%d %d %d " ,j,i,grid[j][i]);
}
}
return grid[n-1][m-1];
}
边栏推荐
- Data analysis learning records -- complete a simple one-way ANOVA with Excel
- [Solved] Splunk: Cannot get username when all users are selected“
- stop slave卡住--事务的事件没有复制完整
- Splunk audit setting
- Addition, deletion, modification and query of handwritten ORM (object relationship mapping)
- Chow-Liu Tree
- 設置單擊右鍵可以選擇用VS Code打開文件
- Qt QScrollArea
- [npuctf2020]ezlogin XPath injection
- Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code
猜你喜欢

STM32之ADC
![P7072 [CSP-J2020] 直播获奖](/img/bc/fcbc2b1b9595a3bd31d8577aba9b8b.png)
P7072 [CSP-J2020] 直播获奖

Configuration clic droit pour choisir d'ouvrir le fichier avec vs Code

Value sequence < detailed explanation of daily question >

海思3559万能平台搭建:在截获的YUV图像上画框

LeetCode 968. Monitor binary tree

中国信通院、清华大学、腾讯安全,云原生安全产学研用强强联合!

Start from the bottom structure to learn the customization and testing of FPGA --- Xilinx ROM IP

boot actuator - prometheus使用

E-commerce system microservice architecture
随机推荐
[leetcode] most elements [169]
DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
Successfully changed Splunk default URL root path
静态文件显示问题
Innovation strength is recognized again! Tencent security MSS was the pioneer of cloud native security guard in 2022
[羊城杯2020]easyphp
悬镜安全在RSAC2022上斩获Global InfoSec Awards四项大奖
STM32串口DAM接收253字节就死机原因排查
Distributed monitoring system ZABBIX
Boot actuator - Prometheus use
Go condition variable
Golang interview finishing three resumes how to write
泛型与反射,看这篇就够了
严守工期,确保质量,这家AI数据标注公司做到了!
go 条件变量
【硬件】标准阻值的由来
xshell配置xforward转发火狐浏览器
Jerry's fast touch does not respond [chapter]
[leetcode] reverse the word III in the string [557]
编辑卡顿