package leetcode;

import java.util.Arrays;
import java.util.List;

/**
 * https://leetcode.com/problems/brick-wall/
 */
public class Problem554 {
    public int leastBricks(List<List<Integer>> wall) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem554 prob = new Problem554();
        System.out.println(prob.leastBricks(Arrays.asList(
            Arrays.asList(1, 2, 2, 1),
            Arrays.asList(3, 1, 2),
            Arrays.asList(1, 3, 2),
            Arrays.asList(2, 4),
            Arrays.asList(3, 1, 2),
            Arrays.asList(1, 3, 3, 1)
        ))); // 2
    }
}

@@ -54,20 +54,68 @@
 va.util.
-List
+HashMap;%0Aimport java.util.List;%0Aimport java.util.Map
 ;%0A%0A/**%0A 
@@ -255,424 +255,686 @@
     
-// TODO%0A        return 0
+int max = 0;%0A        Map%3CInteger, Integer%3E map = new HashMap%3C%3E()
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem554 prob = new Problem554();%0A        System.out.println(prob.leastBricks(Arrays.asList(%0A            Arrays.asList(1, 2, 2, 1),%0A            Arrays.asList(3, 1, 2),%0A            Arrays.asList(1, 3, 2),%0A            Arrays.asList(2, 4),%0A            Arrays.asList(3, 1, 2),%0A            Arrays.asList(1, 3, 3, 1)%0A        ))); // 2
+for (List%3CInteger%3E row : wall) %7B%0A            int totalLength = 0;%0A            for (int i = 0; i %3C row.size() - 1; i++) %7B%0A                totalLength += row.get(i);%0A                if (!map.containsKey(totalLength)) %7B%0A                    int count = 1;%0A                    max = Math.max(max, count);%0A                    map.put(totalLength, count);%0A                %7D else %7B%0A                    int count = map.get(totalLength) + 1;%0A                    max = Math.max(max, count);%0A                    map.put(totalLength, count);%0A                %7D%0A            %7D%0A        %7D%0A        return wall.size() - max;
 %0A   

Solve problem 554