Skip to content

Commit 3e71332

Browse files
authored
Update maximum-and-sum-of-array.py
1 parent 6a9d801 commit 3e71332

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Python/maximum-and-sum-of-array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ def memoiztion(i, mask): # i is meta data, which could be derived from mask, ju
116116
base = 1
117117
for slot in xrange(1, numSlots+1):
118118
if mask//base%3:
119-
lookup[mask] = max(lookup[mask], (x&slot)+memoiztion(i+1, mask-base))
119+
lookup[mask] = max(lookup[mask], (x&slot)+memoiztion(i-1, mask-base))
120120
base *= 3
121121
return lookup[mask]
122122

123123
lookup = [-1]*(3**numSlots)
124124
lookup[0] = 0
125-
return memoiztion(0, 3**numSlots-1)
125+
return memoiztion(2*numSlots-1, 3**numSlots-1)

0 commit comments

Comments
 (0)