public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        if (obstacleGrid == null || obstacleGrid.length == 0
                || obstacleGrid[0].length == 0)
            return 0;
        int row = obstacleGrid.length;
        int col = obstacleGrid[0].length;
        
        int[] path = new int[col];
        
        if (obstacleGrid[row-1][col-1] == 1)
            return 0;
        
        path[col-1] = 1;

        for (int i = row-1; i >= 0; i--) {
            if (obstacleGrid[i][col-1] == 0 && path[col-1] == 1)
                path[col-1] = 1;
            else 
                path[col-1] = 0;
            for (int j = col-2; j >= 0; j--) {
                if (obstacleGrid[i][j] == 1)
                    path[j] = 0;
                else
                    path[j] += path[j+1];
            }
        }
        return path[0];
    }