public int uniquePathsWithObstacles(int[][] obstacleGrid) {
        if(obstacleGrid == null || obstacleGrid.length == 0){
            return 0;
        }
        int nr = obstacleGrid.length;
        int nc = obstacleGrid[0].length;

        int [][] DP = new int[nr][nc];
        for(int i = 0; i < nc; ++i){
            if(obstacleGrid[0][i] != 1) DP[0][i] = 1;
            else break;
        }

        for(int i = 0; i < nr; ++i){
            if(obstacleGrid[i][0] != 1) DP[i][0] = 1;
            else break;
        }

        for(int i = 1; i < nr; ++i){
            for(int j = 1; j < nc; ++j){
                if(obstacleGrid[i][j] == 1) DP[i][j] = 0;
                else DP[i][j] = DP[i][j-1] + DP[i-1][j];
            }
        }
        return DP[nr-1][nc-1];
    }