-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_42898.java
More file actions
27 lines (25 loc) · 837 Bytes
/
_42898.java
File metadata and controls
27 lines (25 loc) · 837 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
class Solution {
static int[][] Map;
public int solution(int m, int n, int[][] puddles) {
Map = new int[m][n];
for(int[] p : puddles){
Map[p[0]-1][p[1]-1] = -1;
}
Map[0][0] = 1;
for(int r=0; r<m; r++){
for(int c=0; c<n; c++){
if(Map[r][c]==-1) continue;
int fromTop = (r-1>=0 && Map[r-1][c]!=-1) ? Map[r-1][c] : 0;
int fromLeft = (c-1>=0 && Map[r][c-1]!=-1) ? Map[r][c-1] : 0;
Map[r][c] += (fromTop + fromLeft) % 1000000007;
}
}
// for(int r=0; r<m; r++){
// for(int c=0; c<n; c++){
// System.out.printf("%3d",Map[r][c]);
// }
// System.out.println();
// }
return Map[m-1][n-1];
}
}