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 350b649 + 6a6971a commit 1ea21f6Copy full SHA for 1ea21f6
csharp/0256-paint-house.cs
@@ -0,0 +1,17 @@
1
+class Solution
2
+{
3
+ public int MinCost(int[][] costs)
4
+ {
5
+ int[] previousRow = new int[3];
6
+ for (int i = 0; i < costs.Length; i++)
7
8
+ int currentRowHouse0 = costs[i][0] + Math.Min(previousRow[1], previousRow[2]);
9
+ int currentRowHouse1 = costs[i][1] + Math.Min(previousRow[0], previousRow[2]);
10
+ int currentRowHouse2 = costs[i][2] + Math.Min(previousRow[0], previousRow[1]);
11
+ previousRow[0] = currentRowHouse0;
12
+ previousRow[1] = currentRowHouse1;
13
+ previousRow[2] = currentRowHouse2;
14
+ }
15
+ return Math.Min(Math.Min(previousRow[0], previousRow[1]), previousRow[2]);
16
17
+}
0 commit comments