当前位置:网站首页>Unique paths II of leetcode topic analysis
Unique paths II of leetcode topic analysis
2022-06-23 08:39:00 【ruochen】
Follow up for "Unique Paths":
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as 1 and 0 respectively in the grid.
For example,
There is one obstacle in the middle of a 3x3 grid as illustrated below.
[
0,0,0,
0,1,0,
0,0,0
]
The total number of unique paths is 2.
Note: m and n will be at most 100.
public int uniquePathsWithObstacles(int[][] obstacleGrid) {
if (obstacleGrid == null || obstacleGrid[0] == null) {
return 0;
}
if (obstacleGrid[0][0] == 1) {
return 0;
}
int m = obstacleGrid.length;
int n = obstacleGrid[0].length;
int[][] dp = new int[m][n];
for (int y = 1; y < n; y++) {
if (obstacleGrid[0][y] == 0) {
dp[0][y] = 1;
} else {
break;
}
}
for (int x = 1; x < m; x++) {
if (obstacleGrid[x][0] == 0) {
dp[x][0] = 1;
} else {
break;
}
}
for (int y = 1; y < n; y++) {
for (int x = 1; x < m; x++) {
if (obstacleGrid[x][y] == 1) {
dp[x][y] = 0;
} else {
dp[x][y] = dp[x - 1][y] + dp[x][y - 1];
}
}
}
return dp[m - 1][n - 1];
}边栏推荐
- 十多年前的入职第一天
- Pyspark on HPC (Continued): reasonable partition processing and consolidated output of a single file
- 6-shining laser application of calayer
- Which one is better for rendering renderings? 2022 latest measured data (IV)
- List接口三个子实现类
- List interface three sub implementation classes
- Object.defineProperty() 和 数据代理
- 如何评价代码质量
- (resolved) difference between leftmost prefix and overlay index
- Map接口及其子实现类
猜你喜欢

最常用的5中流ETL模式

Vulnhub | DC: 3 |【实战】
![[paper notes] catching both gray and black swans: open set supervised analog detection*](/img/52/787b25a9818cfc6a1897af81d41ab2.png)
[paper notes] catching both gray and black swans: open set supervised analog detection*

通信方式总结及I2C驱动详解

How to start Jupiter notebook in CONDA virtual environment

目标检测中的多尺度特征结合方式

Implementation of AVL tree

The first day of employment more than ten years ago

Object.defineProperty() 和 数据代理
![Vulnhub | dc: 3 | [actual combat]](/img/97/e5ba86f2694fe1705c13c60484cff6.png)
Vulnhub | dc: 3 | [actual combat]
随机推荐
目标检测中的多尺度特征结合方式
Pyspark on HPC (Continued): reasonable partition processing and consolidated output of a single file
Android kotlin coroutines KTX extension
[cross border e-commerce solutions] lighthouse will be used for pure IP expansion of new business - continuous efforts!
Do not put files with garbled names into the CFS of NFS protocol
Arclayoutview: implementation of an arc layout
Arthas vmtool命令小结
4-绘制椭圆、使用定时器
2-用线段构成图形、坐标转换
kibana 重建index后,如何恢复Visualizations和 Dashboards
Go data types (II) overview of data types supported by go and Boolean types
Focus! Ten minutes to master Newton convex optimization
Image segmentation - improved network structure
Object. Defineproperty() and data broker
Implementation of AVL tree
自组织映射神经网络(SOM)
Spirit matrix for leetcode topic analysis
Lighthouse cloud desktop experience
5-旋转的小菊-旋转画布和定时器
Why use growth neural gas network (GNG)?