Skip to content

Commit

Permalink
fix uniquePaths.II solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ehds authored and haoel committed Mar 18, 2019
1 parent 0674c9b commit 1965803
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions algorithms/cpp/uniquePaths/uniquePaths.II.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
using namespace std;

//As same as DP solution with "Unique Path I", just need to consider the obstacles.
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) {
vector< vector<int> > v = obstacleGrid;
int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {

int row =obstacleGrid.size();
int col = obstacleGrid[0].size();
vector<vector<unsigned int>> v (row, vector<unsigned int>(col, 0));

unsigned int max=0;
for (int i=0; i<obstacleGrid.size(); i++){
for (int j=0; j<obstacleGrid[i].size(); j++){
for (int i=0; i<row; i++){
for (int j=0; j<col; j++){
if(obstacleGrid[i][j] == 1){
max = v[i][j] = 0;
} else {
Expand All @@ -59,7 +63,7 @@ int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
int row = obstacleGrid.size();
int col = obstacleGrid[0].size();

vector< vector <int> > dp (row, vector<int>(col, 0));
vector< vector <unsigned int> > dp (row, vector<unsigned int>(col, 0));

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

0 comments on commit 1965803

Please sign in to comment.