当前位置:网站首页>Leetcode63. Different paths II
Leetcode63. Different paths II
2022-07-29 00:01:00 【Java full stack R & D Alliance】
Title transmission address :https://leetcode.cn/problems/unique-paths-ii/
Operational efficiency :
The code is as follows :
public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
int m = obstacleGrid.length-1;
int n = obstacleGrid[0].length-1;
return uniquePaths(m, n, obstacleGrid);
}
public static int uniquePaths(int m, int n, int[][] obstacleGrid) {
HashMap<String, Integer> map = new HashMap<>();
return uniqPathsWithMap(m, n, obstacleGrid, map);
}
public static int uniqPathsWithMap(int m, int n, int[][] obstacleGrid, HashMap<String, Integer> map) {
if (obstacleGrid[m][n] == 1) {
return 0;
}
String key = m + ":" + n;
if (map.containsKey(key)) {
return map.get(key);
}
// Dealing with border situations
if (m == 0) {
while (n>0){
if(obstacleGrid[0][n-1]==1){
return 0;
}
n--;
}
return 1;
}
if(n==0){
while (m>0){
if(obstacleGrid[m-1][0]==1){
return 0;
}
m--;
}
return 1;
}
// If you want to walk to (m,n) coordinates , Yes 2 Maybe , The first is from (m-1,n) To (m,n), The first 2 One is from (m,n-1) To (m,n)
int i = uniqPathsWithMap(m - 1, n, obstacleGrid, map) + uniqPathsWithMap(m, n - 1, obstacleGrid, map);
map.put(m + ":" + n, i);
return i;
}
边栏推荐
- Please briefly describe the respective characteristics of list, set and map type sets (briefly describe three different inheritance methods)
- Equipped with a new generation of ultra safe cellular batteries, Sihao aipao is available from 139900 yuan
- Best practices for migration of kingbasees v8.3 to v8.6 of Jincang database (2. Compatibility of kingbasees v8.3 and v8.6)
- Jincang database kingbasees client programming interface guide ODBC (5. Development process)
- Yolov5 learning notes (I) -- principle overview
- Uricase - Characteristics of uricase in Worthington pig liver:
- VS2005透过SourceOffSite访问VSS2005的设置方法「建议收藏」
- 1-6 state and binding events
- Multisensor fusion positioning (III) -- inertial technology
- Powercli VMware vCenter deploys conventional new VMS in batch through self built PXE server with one click
猜你喜欢

Leetcode62. 不同路径

Leetcode59. 螺旋矩阵 II

以JSP为视图解析器搭建SSM项目

With the help of rpa+lcap, the enterprise treasurer management can be upgraded digitally

【C】替换空格,宏实现整数的二进制奇偶位交换

CANoe应用案例之DoIP通信

Uricase - Characteristics of uricase in Worthington pig liver:

Equipped with a new generation of ultra safe cellular batteries, Sihao aipao is available from 139900 yuan

Powercli VMware vCenter deploys conventional new VMS in batch through self built PXE server with one click

The failure rate is as high as 80%. How to correctly complete the strategic planning of digital transformation?
随机推荐
Briefly introduce the working principle and characteristics of block cipher encryption block link mode (cryptography shift cipher encryption and decryption)
Js判断数据类型的4种⽅式
Jincang database kingbasees client programming interface guide ODBC (2. Overview)
Leetcode59. 螺旋矩阵 II
Explanation of history and chemical properties of Worthington ribonuclease B
什么是驱动程序签名,驱动程序如何获取数字签名?
leetcode 763. Partition Labels 划分字母区间(中等)
有效供应链管理的八大绩效分析指标(上)
迅为IMX6开发板QT系统创建AP热点基于RTL8723-交叉编译iptables
请简述list,set,map类型的集合的各自特点(简述三种不同的继承方式下)
1-7 解决类中方法的this指向问题
websocket心跳机制(保活机制)
Worthington丨Worthington胰蛋白酶化学性质及相关研究
PowerCLi VMware vCenter 通过自建的PXE Server一键批量部署常规New-VM
1-7 solve the problem of this pointing of methods in classes
ISO 13400(DoIP)标准解读
数据中台的那些“经验与陷阱”
简述分组密码的加密分组链接模式的工作原理及其特点(密码学移位密码加密解密)
SAP temporary tablespace error handling
Those "experiences and traps" in the data center