当前位置:网站首页>Leetcode64. Minimum path sum
Leetcode64. Minimum path sum
2022-07-29 00:01:00 【Java full stack R & D Alliance】
Title transmission address : https://leetcode.cn/problems/minimum-path-sum/
Operational efficiency :
The code is as follows :
public int minPathSum(int[][] grid) {
// The coordinates of the lower right corner
int m = grid.length - 1;
int n = grid[0].length - 1;
HashMap<String,Integer> map = new HashMap<>();
int path = minPath(m, n, grid,map);
return path;
}
public int minPath(int m, int n, int[][] grid, HashMap<String,Integer> map) {
String key = m + ":" + n;
if(map.containsKey(key)){
return map.get(key);
}
// Dealing with border situations
if (m == 0) {
int path = grid[0][n];
while (n > 0) {
path += grid[0][n - 1];
n--;
}
return path;
}
if (n == 0) {
int path = grid[m][0];
while (m > 0) {
path += grid[m-1][0];
m--;
}
return path;
}
// Go to the (m,n) The location is 2 Seed walking method , The first is from (m-1,n) To (m,n) The second is from the (m,n-1) To (m,n)
int i = minPath(m - 1, n, grid,map);
int j = minPath(m, n - 1, grid,map);
int res = Math.min(i, j) + grid[m][n];
map.put(key,res);
return res;
}
边栏推荐
- Review of categories 1-4
- What is a driver signature and how does the driver get a digital signature?
- Worthington核糖核酸酶B历史和化学性质说明
- Zabbix 5.0 使用自带Redis模版监控
- 1-7 解决类中方法的this指向问题
- 【MySQL 8】Generated Invisible Primary Keys(GIPK)
- Uricase - Characteristics of uricase in Worthington pig liver:
- VS2005 accesses the setting method "recommended collection" of vss2005 through sourceoffsite
- Powercli batch add esxi to vCenter
- 齐博建站指南(艾戈勒)
猜你喜欢

EN 1935 building hardware. Single axis hinge - CE certification

Powercli batch add esxi to vCenter

电商数据模型设计

What is a driver signature and how does the driver get a digital signature?

Multi sensor fusion positioning (I) -- 3D laser odometer

Pycharm configuring the running environment

Deep analysis of integrated learning AdaBoost

Urease -- Characteristics and determination scheme of Worthington jack bean urease

VMware VCSA 7.0 Install

EN 1873屋面用装配附件.塑料单个屋面灯—CE认证
随机推荐
EN 12101-8:2011 smoke dampers for smoke and heat control systems - CE certification
websocket心跳机制(保活机制)
The failure rate is as high as 80%. How to correctly complete the strategic planning of digital transformation?
请简述list,set,map类型的集合的各自特点(简述三种不同的继承方式下)
电商数据模型设计
leetcode 763. Partition Labels 划分字母区间(中等)
VirtualLab基础实验教程-8.傅里叶变换(1)
【MySQL 8】Generated Invisible Primary Keys(GIPK)
SAP oracle 复制新实例后数据库远程连接报错 ora-01031
连接池-归还连接详解(下)
Leetcode60. 排列序列
Briefly introduce the working principle and characteristics of block cipher encryption block link mode (cryptography shift cipher encryption and decryption)
双重for循环优化
Classification and determination method of Worthington stemxyme
Explanation of history and chemical properties of Worthington ribonuclease B
After SAP Oracle replicates a new instance, the remote connection of the database reports an error ora-01031
酪氨酸脱羧酶丨Worthington粪链球菌酪氨酸脱羧酶的特征
PIP image download
实时数仓:网易严选基于Flink的实时数仓实践
Yolov5 learning notes (I) -- principle overview