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.
2 parents e068b92 + f637818 commit 48a95bfCopy full SHA for 48a95bf
java/0256-paint-house.java
@@ -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