Skip to content

Commit

Permalink
Add Java solution for 554. Brick Wall
Browse files Browse the repository at this point in the history
  • Loading branch information
gnohgnij committed Jan 3, 2023
1 parent 8dcc3d2 commit be7d06b
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 be7d06b

Please sign in to comment.