File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
algorithms/cpp/uniquePaths Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 30
30
using namespace std ;
31
31
32
32
// 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
+
35
39
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++){
38
42
if (obstacleGrid[i][j] == 1 ){
39
43
max = v[i][j] = 0 ;
40
44
} else {
@@ -59,7 +63,7 @@ int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
59
63
int row = obstacleGrid.size ();
60
64
int col = obstacleGrid[0 ].size ();
61
65
62
- vector< vector <int > > dp (row, vector<int >(col, 0 ));
66
+ vector< vector <unsigned int > > dp (row, vector<unsigned int >(col, 0 ));
63
67
64
68
dp[0 ][0 ] = obstacleGrid[0 ][0 ] ? 0 : 1 ;
65
69
for (int r=1 ; r<row; r++) {
You can’t perform that action at this time.
0 commit comments