```
if (obstacleGrid.size() == 0 || obstacleGrid[0].size() == 0)
return 0;
int rows = obstacleGrid.size();
int columns = obstacleGrid[0].size();
std::vector<std::vector<int>> ways(rows, std::vector<int>(columns, 0));
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
if (obstacleGrid[i][j] == 1)
ways[i][j] = 0;
else if ((i == 0) && (j == 0))
ways[i][j] = 1;
else if (i == 0)
ways[i][j] = ways[i][j - 1];
else if (j == 0)
ways[i][j] = ways[i - 1][j];
else
ways[i][j] = ways[i - 1][j] + ways[i][j - 1];
}
}
return ways[rows - 1][columns - 1];
```