MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/medium/_0554/Solution.java:17–46  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/10/13 desc :

Source from the content-addressed store, hash-verified

15 * </pre>
16 */
17public class Solution {
18 public int leastBricks(List<List<Integer>> wall) {
19 Map<Integer, Integer> map = new HashMap<>();
20 int width = 0, max = 0;
21 for (List<Integer> sub : wall) {
22 int p = 0;
23 for (int i = 0, len = sub.size() - 1; i < len; ++i) {
24 p += sub.get(i);
25 Integer v = map.get(p);
26 map.put(p, (v == null ? 0 : v) + 1);
27 }
28 }
29 for (Integer integer : map.values()) {
30 if (integer > max) max = integer;
31 }
32 return wall.size() - max;
33 }
34
35 public static void main(String[] args) {
36 Solution solution = new Solution();
37 List<List<Integer>> list = new ArrayList<>();
38 list.add(Arrays.asList(1, 2, 2, 1));
39 list.add(Arrays.asList(3, 1, 2));
40 list.add(Arrays.asList(1, 3, 2));
41 list.add(Arrays.asList(2, 4));
42 list.add(Arrays.asList(3, 1, 2));
43 list.add(Arrays.asList(1, 3, 1, 1));
44 System.out.println(solution.leastBricks(list));
45 }
46}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected