-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrickWall.java
More file actions
33 lines (28 loc) · 857 Bytes
/
BrickWall.java
File metadata and controls
33 lines (28 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package medium;
import java.util.*;
/**
* ClassName: BrickWall.java
* Author: chenyiAlone
* Create Time: 2019/12/4 15:12
* Description: No.554 Brick Wall
*/
public class BrickWall {
public int leastBricks(List<List<Integer>> wall) {
Map<Integer, Integer> map = new HashMap<>();
int ret = wall.size();
for (List<Integer> list : wall) {
int total = 0;
for (int i = 0; i < list.size(); i++) {
total += list.get(i);
if (i != list.size() - 1) {
if (map.containsKey(total))
map.put(total, map.get(total) + 1);
else
map.put(total, 1);
ret = Math.min(ret, wall.size() - map.get(total));
}
}
}
return ret;
}
}