Skip to content

Commit 660c9ba

Browse files
committed
revised the errors in the code
1. in function findMaxBlock definition, for i in range(0,8) instead of for i in range(0,7) 2. the initialization of cntarr is wrong, you cannot initialize an empty array like this in python, please refer to https://docs.python.org/2/faq/programming.html#how-do-i-create-a-multidimensional-list 3. I think the "global size" in getMaxOnes function is not needed.
1 parent 81891fa commit 660c9ba

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/chapter19dynamicprogramming/GetMaxOnes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def findMaxBlock(A, r, c, L, H, size):
2525
maxsize = size
2626
# search in eight directions
2727
direction = [[-1, 0], [-1, -1], [0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1]];
28-
for i in range(0, 7):
28+
for i in range(0, 8):
2929
newi = r + direction[i][0]
3030
newj = c + direction[i][1]
3131
val = getval (A, newi, newj, L, H)
@@ -37,7 +37,6 @@ def findMaxBlock(A, r, c, L, H, size):
3737

3838
def getMaxOnes(A, rmax, colmax):
3939
global maxsize
40-
global size
4140
global cntarr
4241
for i in range(0, rmax):
4342
for j in range(0, colmax):
@@ -51,6 +50,6 @@ def getMaxOnes(A, rmax, colmax):
5150
colmax = 5
5251
maxsize = 0
5352
size = 0
54-
cntarr = rmax * [colmax * [0]]
53+
cntarr = [[colmax * [0]] for i in range(rmax)]
5554
print ("Number of maximum 1s are ")
5655
print getMaxOnes(zarr, rmax, colmax)

0 commit comments

Comments
 (0)