当前位置:网站首页>63. different paths II
63. different paths II
2022-06-13 00:11:00 【anieoo】
Original link :63. Different paths II
solution:
The standard dp, Just add the judgment of obstacles during initialization and circulation
class Solution {
public:
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int m = obstacleGrid.size();
int n = obstacleGrid[0].size();
vector<vector<int>> dp(m, vector<int> (n, 0));
// Initialize initial condition
bool flag = false;
for(int i = 0;i < m;i++) {
if(obstacleGrid[i][0] == 1) flag = true;
if(!flag) dp[i][0] = 1;
}
flag = false;
for(int j = 0;j < n;j++) {
if(obstacleGrid[0][j] == 1) flag = true;
if(!flag) dp[0][j] = 1;
}
for(int i = 1;i < m;i++)
for(int j = 1;j < n;j++) {
if(obstacleGrid[i][j] == 1) continue;
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
return dp[m - 1][n - 1];
}
};边栏推荐
- The PMP examination time in March 2022 is set -- "March 27"
- How to load 100000 pieces of data in leaflet
- How to gracefully solve the offset problem of Baidu and Gaode maps in leaflet
- 测试平台系列(97) 完善执行case部分
- leaflet如何加载10万条数据
- How to use Huawei cloud disaster tolerance solution to replace disaster recovery all-in-one machine
- Actual combat | UI automation test framework design and pageobject transformation
- 电商员工离职后将产品价格改为1折出售,已被刑拘
- Do you have to read for PMP?
- Start of u-boot S analysis (IV)
猜你喜欢
![[hcie discussion] multicast igmp-a](/img/1a/74c6e698c9a6a6c7a4c32153a0a277.png)
[hcie discussion] multicast igmp-a

leaflet中如何优雅的解决百度、高德地图的偏移问题

H5时代leaflet中还在用DivIcon?

进程间通信-共享内存shmat

如何让矢量瓦片配图神器maputnik支持 geoserver

How to pass the PMP review?

How does idea switch the interface to Chinese

浏览器缓存的执行流程
![[matlab] symbol calculation](/img/a5/7682a465ca2813a83114c091580c53.png)
[matlab] symbol calculation

OSM map local publishing - how to generate vector maps of provinces and cities
随机推荐
Design MySQL table structure for message queue to store information data
[matlab] symbol calculation
leaflet中如何通过透明度控制layerGroup的显示隐藏
Building crud applications in golang
Introduction to business rules service on SAP Business Technology Platform (BTP)
How SAP ui5 uses manifest JSON file defines third-party library dependencies
Apispace empty number detection API interface is free and easy to use
21 Chundong University blasting safety online peacetime operation 123 [standard answer]
PMP test experience
H5时代leaflet中还在用DivIcon?
进程间通信-共享内存shmat
How to quickly query the mobile phone number home and operator
leaflet如何优雅的展示重叠点位的气泡窗口
TypeError: wave.ensureState is not a function
Talent Weekly - 5
[matlab] matrix operation
Do you have to read for PMP?
array
PMP registration conditions, time, cost, new version related information
2022年3月11日记:王老师的春天,奇异的模板模式