Skip to content

Commit

Permalink
Update paint-house-ii.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Aug 20, 2015
1 parent d286902 commit 207790b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Python/paint-house-ii.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ def minCostII(self, costs):
k = len(costs[0])
min_cost = [costs[0], [0] * k]
for i in xrange(1, n):
min_1st, min_2nd = float("inf"), float("inf")
smallest, second_smallest = float("inf"), float("inf")
for j in xrange(k):
if min_1st >= min_cost[(i - 1) % 2][j]:
min_1st, min_2nd = min_cost[(i - 1) % 2][j], min_1st
elif min_2nd >= min_cost[(i - 1) % 2][j]:
min_2nd = min_cost[(i - 1) % 2][j]
if min_cost[(i - 1) % 2][j] < smallest:
smallest, second_smallest = min_cost[(i - 1) % 2][j], smallest
elif min_cost[(i - 1) % 2][j] < second_smallest:
second_smallest = min_cost[(i - 1) % 2][j]
for j in xrange(k):
min_j = min_1st if min_cost[(i - 1) % 2][j] != min_1st else min_2nd
min_j = smallest if min_cost[(i - 1) % 2][j] != smallest else second_smallest
min_cost[i % 2][j] = costs[i][j] + min_j

return min(min_cost[(n - 1) % 2])

0 comments on commit 207790b

Please sign in to comment.