public class UniquePaths
{
public UniquePaths(){}
public int uniquePathsWithObstacles(int[][] obstacleGrid)
{
if(obstacleGrid.length == 0 ||
obstacleGrid[0].length == 0)
{return 0;}
int m= obstacleGrid.length;
int n= obstacleGrid[0].length;
int[] numpath= new int[n];
int index= n;
numpath[0]= 1;
for(int i=0;i<n;i++)
{
if(obstacleGrid[0][i] == 0)
{numpath[i]=1;}
else
{index=i;break;}
}
for(int i=index;i<n;i++)
{numpath[i]= 0;}
for(int i=1;i<m;i++)
{
if(obstacleGrid[i][0] == 1)
{numpath[0]=0;}
for(int j=1;j<n;j++)
{
if(obstacleGrid[i][j] == 0)
{numpath[j] += numpath[j-1];}
else
{numpath[j]= 0;}
}
}
return numpath[n-1];
}
}