Skip to content

Commit 23e686a

Browse files
authored
Update maximum-value-of-k-coins-from-piles.py
1 parent 96a3e94 commit 23e686a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Python/maximum-value-of-k-coins-from-piles.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ def maxValueOfCoins(self, piles, k):
1212
dp = [0]
1313
for pile in piles:
1414
new_dp = [0]*min(len(dp)+len(pile), k+1)
15-
for j in xrange(len(dp)):
15+
for i in xrange(len(dp)):
1616
curr = 0
17-
for l in xrange(min(k-j, len(pile))+1):
18-
new_dp[j+l] = max(new_dp[j+l], dp[j]+curr)
19-
curr += pile[l] if l < len(pile) else 0
17+
for j in xrange(min(k-i, len(pile))+1):
18+
new_dp[i+j] = max(new_dp[i+j], dp[i]+curr)
19+
curr += pile[j] if j < len(pile) else 0
2020
dp = new_dp
2121
return dp[-1]

0 commit comments

Comments
 (0)