Skip to content

Commit 1ea21f6

Browse files
authored
Merge pull request #2010 from thuanle123/0256-paint-house
create 0256-paint-house-csharp
2 parents 350b649 + 6a6971a commit 1ea21f6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

csharp/0256-paint-house.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)