Skip to content

Commit 5d42a33

Browse files
authored
Create 0554-Brick-Wall.cs
File Modified: 0554-brick-wall.cs Language(s) Used: C# Submission URL: https://leetcode.com/problems/brick-wall/submissions/941197569/
1 parent b3d6abd commit 5d42a33

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

csharp/0554-brick-wall.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class Solution {
2+
public int LeastBricks(IList<IList<int>> wall) {
3+
Dictionary<int, int> countGap = new Dictionary<int, int>();
4+
countGap[0] = 0;
5+
6+
foreach (var row in wall) {
7+
int total = 0;
8+
for (int i = 0; i < row.Count - 1; i++) {
9+
int brick = row[i];
10+
total += brick;
11+
if (!countGap.ContainsKey(total)) {
12+
countGap[total] = 0;
13+
}
14+
countGap[total]++;
15+
}
16+
}
17+
18+
return wall.Count - countGap.Values.Max();
19+
}
20+
}

0 commit comments

Comments
 (0)