We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 230d578 commit 6be9690Copy full SHA for 6be9690
l33tcode/paint-house.go
@@ -0,0 +1,29 @@
1
+package main
2
+
3
+import (
4
+ "math"
5
+)
6
7
+func minCost(costs [][]int) int {
8
+ if len(costs) == 0 {
9
+ return 0
10
+ }
11
12
+ houses := len(costs)
13
+ colors := len(costs[0])
14
+ for pos := range make([]int, houses) {
15
+ if pos != 0 {
16
+ for colorCur := range make([]int, colors) {
17
+ curCost := costs[pos][colorCur]
18
+ costs[pos][colorCur] = math.MaxInt64
19
+ for colorPrev := range make([]int, colors) {
20
+ if colorCur != colorPrev {
21
+ costs[pos][colorCur] = int(math.Min(float64(costs[pos][colorCur]), float64(curCost+costs[pos-1][colorPrev])))
22
23
24
25
26
27
28
+ return int(math.Min(math.Min(float64(costs[houses-1][0]), float64(costs[houses-1][1])), float64(costs[houses-1][2])))
29
+}
0 commit comments