Clear Java Solution easy to understand


  • 0
    L

    The purpose is to find a col with most edges.First I choose Array[i], which i means the numbers of edges in col[i].But it cause OOM, so I change to Map.

    public class Solution {
        public static int leastBricks(List<List<Integer>> wall) {
            HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();//<edge,num>
            for(List<Integer> rows : wall){
                int edge = 0;
                for(int brick : rows){
                    if(edge != 0)
                        map.put(index,map.getOrDefault(edge,0) + 1);
                    edge += brick;
                }
            }
            int max = 0;
            for(int m : map.values()){
                max = Math.max(max, m);
            }
            return wall.size() - max;
        }
    }
    

Log in to reply
 

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