当前位置:网站首页>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];
}
边栏推荐
- Jerry's built-in shutdown current is 1.2ua, and then it can't be turned on by long pressing [chapter]
- Lambda expression: an article takes you through
- Go language sqlx library operation SQLite3 database addition, deletion, modification and query
- DTM distributed transaction manager PHP collaboration client V0.1 beta release!!!
- Go multithreaded data search
- Boot actuator - Prometheus use
- Lc173. Binary search tree iterator
- 【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
- Pytorch training CPU usage continues to grow (Bug)
- Jerry's fast touch does not respond [chapter]
猜你喜欢

设置单击右键可以选择用VS Code打开文件
![The kth largest element in the [leetcode] array [215]](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
The kth largest element in the [leetcode] array [215]

情感对话识别与生成简述

Go语言sqlx库操作SQLite3数据库增删改查

Niuke network: maximum submatrix

E-commerce system microservice architecture

MySQL查询附近的数据.并按距离进行排序.

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

Methods to solve the tampering of Chrome browser and edeg browser homepage

設置單擊右鍵可以選擇用VS Code打開文件
随机推荐
LeetCode 968. 监控二叉树
【板栗糖GIS】arcmap—为什么使用自定义捕捉的时候,经典捕捉的勾要去掉呢?
Lambda表达式:一篇文章带你通透
Generics and reflection, this is enough
【板栗糖GIS】arcscene—如何做出有高度的高程图
STM32串口DAM接收253字节就死机原因排查
[Yangcheng cup 2020] easyphp
antd组件upload上传xlsx文件,并读取文件内容
mysql重置密码,忘记密码,重置root密码,重置mysql密码
剑指 Offer II 099. 最小路径之和-双百代码
MySQL reset password, forget password, reset root password, reset MySQL password
[chestnut sugar GIS] ArcMap - why should the tick of classic capture be removed when using custom capture?
Dahua cloud native load balancing article - the passenger flow of small restaurants has increased
設置單擊右鍵可以選擇用VS Code打開文件
Xshell configuration xforward forwarding Firefox browser
How does Jerry test the wrong touch rate of keys [chapter]
ServletContext learning diary 1
【板栗糖GIS】global mapper 如何通过dsm批量制作贴地等高线
电路设计者常用的学习网站
WebRTC音视频采集和播放示例及MediaStream媒体流解析