From 6a6971a5248d663c9c3e4ef201a12361e062e82f Mon Sep 17 00:00:00 2001 From: Thuan Le Date: Thu, 12 Jan 2023 19:32:20 -0800 Subject: [PATCH] create 0256-paint-house-csharp --- csharp/0256-paint-house.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 csharp/0256-paint-house.cs diff --git a/csharp/0256-paint-house.cs b/csharp/0256-paint-house.cs new file mode 100644 index 000000000..2660b01fa --- /dev/null +++ b/csharp/0256-paint-house.cs @@ -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]); + } +} \ No newline at end of file