forked from neetcode-gh/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request neetcode-gh#2010 from thuanle123/0256-paint-house
create 0256-paint-house-csharp
- Loading branch information
Showing
1 changed file
with
17 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |