Skip to content

Commit e7c79e8

Browse files
authored
Merge pull request neetcode-gh#1859 from gnohgnij/0554-brick-wall
Create: 0554-brick-wall.java
2 parents d5d7762 + be7d06b commit e7c79e8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

java/0554-brick-wall.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int leastBricks(List<List<Integer>> wall) {
3+
Map<Integer, Integer> map = new HashMap<>();
4+
int maxGaps = 0;
5+
6+
for(List<Integer> row : wall) {
7+
int pos = 0;
8+
for(int i=0; i<row.size()-1; i++) {
9+
pos += row.get(i);
10+
map.put(pos, map.getOrDefault(pos, 0)+1);
11+
maxGaps = Math.max(maxGaps, map.get(pos));
12+
}
13+
}
14+
15+
return wall.size() - maxGaps;
16+
}
17+
}

0 commit comments

Comments
 (0)