Analysis:
Typical dynamic programming issue. We define dp[i][j] represents when last i houses painted with minimum cost when i-1th house painted with jth color
The we have:
dp = [[0 for i in xrange(3)] for j in xrange(len(costs)+1)]
Time Complexity:
- O(n)
Space Complexity:
- O(n)
Code
1 | class Solution: |