当前位置:网站首页>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;
}
边栏推荐
- 1-5 类式组件
- Build SSM project with JSP as view parser
- Oracle create tablespaces and users
- Worthington RNA determination detailed introduction
- @Transactional 注解使用详解
- 通配符 SSL/TLS 证书
- The failure rate is as high as 80%. How to correctly complete the strategic planning of digital transformation?
- JS高级 之 ES6~ES13 新特性
- ZABBIX 5.0 uses its own redis template for monitoring
- PMP Exam countdown, look at 3A pass bag!
猜你喜欢

ZABBIX 5.0 uses its own redis template for monitoring

SAP 临时表空间错误处理

Explanation of history and chemical properties of Worthington ribonuclease B

Leetcode63. 不同路径 II

连接池-归还连接详解(下)

Worthington -- Specification of Worthington trypsin inhibitor

Create AP hotspots for imx6 development board QT system based on rtl8723 cross compile iptables

【详细超简单】如何使用WebSocket链接

NAT如何配置地址转换

PHP poster QR code synthesis
随机推荐
1-4 类的复习
脲酶丨Worthington杰克豆脲酶的特性及测定方案
PMP考试倒计时,速看3A通关锦囊!
Kingbasees client programming interface guide ODBC (4. Create data source)
Leetcode59. 螺旋矩阵 II
Type 1-5 components
【MySQL 8】Generated Invisible Primary Keys(GIPK)
@Transactional 注解使用详解
Worthington丨Worthington胰蛋白酶化学性质及相关研究
With the help of rpa+lcap, the enterprise treasurer management can be upgraded digitally
【C】喝汽水,找单身狗问题
Build SSM project with JSP as view parser
EN 1873 assembly accessories for roofing - plastic single roof lamps - CE certification
Please briefly describe the respective characteristics of list, set and map type sets (briefly describe three different inheritance methods)
Worthington - chemical properties and related studies of Worthington trypsin
Powercli batch add esxi to vCenter
Leetcode 763. partition labels divide alphabetic intervals (medium)
Oracle create tablespaces and users
软件设计师的错题汇总
【C】替换空格,宏实现整数的二进制奇偶位交换