Skip to content

Commit 48a95bf

Browse files
Merge pull request neetcode-gh#3455 from Tetsuya3850/patch-6
2 parents e068b92 + f637818 commit 48a95bf

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

java/0256-paint-house.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public int minCost(int[][] costs) {
3+
int[] dp = new int[3];
4+
for (int i = 0; i < costs.length; i++) {
5+
int dp0 = costs[i][0] + Math.min(dp[1], dp[2]);
6+
int dp1 = costs[i][1] + Math.min(dp[0], dp[2]);
7+
int dp2 = costs[i][2] + Math.min(dp[0], dp[1]);
8+
dp = new int[] { dp0, dp1, dp2 };
9+
}
10+
return Arrays.stream(dp).min().getAsInt();
11+
}
12+
}

0 commit comments

Comments
 (0)