From 8849766ece6ae087b379882860e555e1a5c9b46c Mon Sep 17 00:00:00 2001 From: kamyu Date: Thu, 20 Aug 2015 23:53:22 +0800 Subject: [PATCH] Update paint-house-ii.py --- Python/paint-house-ii.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Python/paint-house-ii.py b/Python/paint-house-ii.py index 7418f417e..1fd5f873d 100644 --- a/Python/paint-house-ii.py +++ b/Python/paint-house-ii.py @@ -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]]