-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathav09_matrix.py
58 lines (48 loc) · 1.19 KB
/
av09_matrix.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# compute pathes in matrix 0,0 -> m.n
#avoid obstacles in A
class Solution:
def check_i(self,i,j):
res=True
if i==Solution.maxi:
res=False
else:
next=[i+1,j]
print("next in ", next , Solution.obs )
if next in Solution.obs:
res=False
return res
def check_j(self,i,j):
res=True
if j==Solution.maxj:
res=False
else:
next=[i,j+1]
if next in Solution.obs:
res=False
return res
def step(self, i,j):
if i==Solution.maxi and j==Solution.maxj :
return 1
ni=0
nj=0
if(self.check_i(i,j)==True):
ni=self.step(i+1,j)
if(self.check_j(i,j)==True):
nj=self.step(i,j+1)
print (i, j, "ni, nj" , ni, nj)
return ni+nj
def uniquePathsWithObstacles(self, A):
Solution.obs=A
Solution.maxi=2
Solution.maxj=2
if [0,0] in Solution.obs:
npath=0
else:
npath=self.step(0,0)
return npath
x=Solution()
A=[
[1, 0,]
]
npath=x.uniquePathsWithObstacles(A)
print(npath)