classSolution { public: intuniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { int i, j, m = obstacleGrid.size(), n = obstacleGrid[0].size(); if (m == 1 && n == 1) { if (obstacleGrid[0][0] == 1) { return0; }else{ return1; } } // dp[i][j] represents the number of different paths to reach grid[i][j] vector<vector<int> > dp(m, vector<int>(n, 0));
dp[0][0] = 1; for (i = 1; i < m; i++) { if (obstacleGrid[i - 1][0] != 1 && obstacleGrid[i][0] != 1) { dp[i][0] = 1; } else { break; } }