class Solution { public int uniquePathsWithObstacles(int[][] obstacleGrid) { for(int i=0;i<obstacleGrid.length;i++) for(int j=0;j<obstacleGrid[0].length;j++) obstacleGrid[i][j]=-obstacleGrid[i][j]; obstacleGrid[0][0]=obstacleGrid[0][0]>=0?1:0; for(int i=0;i<obstacleGrid.length;i++) for(int j=0;j<obstacleGrid[0].length;j++) if(obstacleGrid[i][j]>=0) obstacleGrid[i][j]+=(i>0&&obstacleGrid[i-1][j]>=0?obstacleGrid[i-1][j]:0)+(j>0&&obstacleGrid[i][j-1]>=0?obstacleGrid[i][j-1]:0); return Math.max(obstacleGrid[obstacleGrid.length-1][obstacleGrid[0].length-1], 0); } }