easy java solution.


  • 0
    C
    public int leastBricks(List<List<Integer>> wall) {
            HashMap<Integer,Integer> mapper = new HashMap<>();
            int max = 0;
            for(List<Integer> row: wall){
                int val=0;
                for(int i =0;i<row.size()-1;i++){
                    val+=row.get(i);
                    mapper.put(val,mapper.getOrDefault(val,0)+1);
                    max = Math.max(max,mapper.get(val));
                }
            }
            return wall.size()-max;
        }
    

    BTW, there must be some follow ups of this problem. But I can't think more of it.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.