当前位置:网站首页>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;
}
边栏推荐
- 1-5 类式组件
- Linux之yum安装MySQL
- Jincang database kingbasees client programming interface guide ODBC (2. Overview)
- 1-7 solve the problem of this pointing of methods in classes
- Compose 的声明式代码如此简洁?
- SAP oracle 复制新实例后数据库远程连接报错 ora-01031
- Doip communication of canoe application case
- Interpretation of ISO 13400 (doip) standard
- 失败率高达80%,数字化转型如何正确完成战略规划?
- pycharm新建项目
猜你喜欢
多传感器融合定位(三)——惯性技术
Pycharm configuring the running environment
Urease -- Characteristics and determination scheme of Worthington jack bean urease
SAP temporary tablespace error handling
PowerCLi VMware vCenter 通过自建的PXE Server一键批量部署常规New-VM
Powercli VMware vCenter deploys conventional new VMS in batch through self built PXE server with one click
Create AP hotspots for imx6 development board QT system based on rtl8723 cross compile iptables
Multi sensor fusion positioning (I) -- 3D laser odometer
Android studio连接MySQL并完成简单的登录注册功能
使用Pytorch快速训练网络模型
随机推荐
【C】逆序字符串(俩种递归思路)
基于 FPGA 实现数字时钟详细原理讲解及验证结果
数据中台的那些“经验与陷阱”
Compatibility description between kingbasees and Oracle (4. SQL)
Js判断数据类型的4种⽅式
双重for循环优化
Powercli batch add esxi to vCenter
JS advanced ES6 ~ es13 new features
PHP 海报二维码合成
尿酸酶丨Worthington猪肝尿酸酶的特征:
Leetcode64. 最小路径和
fastdfs工作原理(技术原理)
Leetcode63. 不同路径 II
请简述list,set,map类型的集合的各自特点(简述三种不同的继承方式下)
Is the declarative code of compose so concise?
Deep analysis of integrated learning xgboost
NPDP考试需要携带什么?文具携带说明
NAT如何配置地址转换
[TA frost wolf \u may - "hundred people plan"] Figure 3.6 texture compression - inclusion slimming
Please briefly describe the respective characteristics of list, set and map type sets (briefly describe three different inheritance methods)