We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e8dc7af commit a4c7d77Copy full SHA for a4c7d77
1 file changed
binary_matrix
@@ -0,0 +1,33 @@
1
+def binary_matrix(A):
2
+ row, col = len(A), len(A[0])
3
+ dp = [[0 for j in range(col)] for i in range(row)]
4
+ for i in range(row):
5
+ dp[i][0] = A[i][0]
6
+ for j in range(col):
7
+ dp[0][j] = A[0][j]
8
+ for i in range(1, row):
9
+ for j in range(1, col):
10
+ if A[i][j] == 0:
11
+ dp[i][j] = 0
12
+ else:
13
+ dp[i][j] = 1 + min(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1])
14
+ max_ele = dp[0][0]
15
+ max_i, max_j = 0, 0
16
17
18
+ if max_ele < dp[i][j]:
19
+ max_ele = dp[i][j]
20
+ max_i, max_j = i, j
21
+
22
+ k = max_ele
23
+ return k
24
25
26
+M = [[0, 1, 1, 0, 1],
27
+ [1, 1, 0, 1, 0],
28
+ [0, 1, 1, 1, 0],
29
+ [1, 1, 1, 1, 0],
30
+ [1, 1, 1, 1, 1],
31
+ [0, 0, 0, 0, 0]]
32
33
+print(binary_matrix(M))
0 commit comments