Skip to content

Commit 969729f

Browse files
authored
Create 554. Brick Wall
1 parent f7ad706 commit 969729f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

554. Brick Wall

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

0 commit comments

Comments
 (0)