Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2010 from thuanle123/0256-paint-house
Browse files Browse the repository at this point in the history
create 0256-paint-house-csharp
  • Loading branch information
tahsintunan authored Jan 16, 2023
2 parents 350b649 + 6a6971a commit 1ea21f6
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 1ea21f6

Please sign in to comment.