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 207790b commit 8849766
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Python/paint-house-ii.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Time: O(n * k)
# Space: O(k)

class Solution(object):
class Solution2(object):
def minCostII(self, costs):
"""
:type costs: List[List[int]]
:rtype: int
"""
return min(reduce(self.combine, costs)) if costs else 0

def combine(self, tmp, house):
smallest, k, i = min(tmp), len(tmp), tmp.index(min(tmp))
tmp, tmp[i] = [smallest] * k, min(tmp[:i] + tmp[i+1:])
return map(sum, zip(house, tmp))


class Solution2(object):
def minCostII(self, costs):
"""
:type costs: List[List[int]]
Expand Down

0 comments on commit 8849766

Please sign in to comment.