Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1859 from gnohgnij/0554-brick-wall
Browse files Browse the repository at this point in the history
Create: 0554-brick-wall.java
  • Loading branch information
tahsintunan authored Jan 4, 2023
2 parents d5d7762 + be7d06b commit e7c79e8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions java/0554-brick-wall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public int leastBricks(List<List<Integer>> wall) {
Map<Integer, Integer> map = new HashMap<>();
int maxGaps = 0;

for(List<Integer> row : wall) {
int pos = 0;
for(int i=0; i<row.size()-1; i++) {
pos += row.get(i);
map.put(pos, map.getOrDefault(pos, 0)+1);
maxGaps = Math.max(maxGaps, map.get(pos));
}
}

return wall.size() - maxGaps;
}
}

0 comments on commit e7c79e8

Please sign in to comment.