Skip to content

Commit 1965803

Browse files
ehdshaoel
authored andcommitted
fix uniquePaths.II solution
1 parent 0674c9b commit 1965803

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

algorithms/cpp/uniquePaths/uniquePaths.II.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,15 @@
3030
using namespace std;
3131

3232
//As same as DP solution with "Unique Path I", just need to consider the obstacles.
33-
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
34-
vector< vector<int> > v = obstacleGrid;
33+
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
34+
35+
int row =obstacleGrid.size();
36+
int col = obstacleGrid[0].size();
37+
vector<vector<unsigned int>> v (row, vector<unsigned int>(col, 0));
38+
3539
unsigned int max=0;
36-
for (int i=0; i<obstacleGrid.size(); i++){
37-
for (int j=0; j<obstacleGrid[i].size(); j++){
40+
for (int i=0; i<row; i++){
41+
for (int j=0; j<col; j++){
3842
if(obstacleGrid[i][j] == 1){
3943
max = v[i][j] = 0;
4044
} else {
@@ -59,7 +63,7 @@ int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
5963
int row = obstacleGrid.size();
6064
int col = obstacleGrid[0].size();
6165

62-
vector< vector <int> > dp (row, vector<int>(col, 0));
66+
vector< vector <unsigned int> > dp (row, vector<unsigned int>(col, 0));
6367

6468
dp[0][0] = obstacleGrid[0][0] ? 0 : 1;
6569
for (int r=1; r<row; r++) {

0 commit comments

Comments
 (0)