Simple recursive Java solution


#1

public class Solution {
public int uniquePathsWithObstacles(ArrayList<ArrayList> A) {
if(A == null || A.size() <= 0 || A.get(0) == null || A.get(0).size() <= 0){
return 0;
}
// 0 -> m-1, 0 -> n-1
return recUniquePaths(A, 0, A.size(), 0, A.get(0).size());
}

private int recUniquePaths(ArrayList<ArrayList<Integer>> A, int x, int m, int y, int n){
    if(x >= m || y >= n){
        return 0;
    }
    if(A.get(x).get(y).intValue() == 1){
        return 0;
    }
    if(x == m-1 && y == n-1){
        return 1;
    }
    return recUniquePaths(A, x+1, m, y, n) + recUniquePaths(A, x, m, y+1, n);
}

}