Skip to content

Commit

Permalink
create 0256-paint-house-csharp
Browse files Browse the repository at this point in the history
  • Loading branch information
thuanle123 committed Jan 13, 2023
1 parent a14fcbd commit 6a6971a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions csharp/0256-paint-house.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution
{
public int MinCost(int[][] costs)
{
int[] previousRow = new int[3];
for (int i = 0; i < costs.Length; i++)
{
int currentRowHouse0 = costs[i][0] + Math.Min(previousRow[1], previousRow[2]);
int currentRowHouse1 = costs[i][1] + Math.Min(previousRow[0], previousRow[2]);
int currentRowHouse2 = costs[i][2] + Math.Min(previousRow[0], previousRow[1]);
previousRow[0] = currentRowHouse0;
previousRow[1] = currentRowHouse1;
previousRow[2] = currentRowHouse2;
}
return Math.Min(Math.Min(previousRow[0], previousRow[1]), previousRow[2]);
}
}

0 comments on commit 6a6971a

Please sign in to comment.