public static int uniquePathsWithObstacles(int[][] obstacleGrid) {
        if(obstacleGrid.length == 0 || obstacleGrid[0].length == 0) {
            return 0;
        }
        int m = obstacleGrid.length;
        int n = obstacleGrid[0].length;
        //automatically initialized to 0
        int[] rs = new int[n];
        //use dynamic programming to get rs[n], rs[n] is a "rolling array"
        for(int i = 0; i < m; i++) {
            for(int j = 0; j < n; j++) {
                if(obstacleGrid[i][j] == 1) {
                    rs[j] = 0;
                } else {
                    if(i == 0 && j == 0) {
                        rs[j] = 1;
                    } else {
                        rs[j] = (j > 0 ? rs[j-1] : 0) + (i > 0 ? rs[j] : 0);
                    }
                }
            }
        }
        return rs[n-1];
    }