-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob63.java
More file actions
29 lines (27 loc) · 811 Bytes
/
prob63.java
File metadata and controls
29 lines (27 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public int uniquePathsWithObstacles(int[][] arr) {
int n=arr.length;
int m=arr[0].length;
if(arr[0][0]==1 || arr[n-1][m-1]==1)
return 0;
return sol(arr,n,m);
}
public int sol(int[][]arr,int n,int m){
int[][]dp=new int[n][m];
for(int i=n-1;i>=0;i--){
for(int j=m-1;j>=0;j--){
if(i==n-1 && j==m-1 && arr[i][j]==0){
dp[i][j]=1;
continue;
}
int res=0;
if(i+1<n && arr[i+1][j]==0)
res+=dp[i+1][j];
if(j+1<m && arr[i][j+1]==0)
res+=dp[i][j+1];
dp[i][j]=res;
}
}
return dp[0][0];
}
}