my java solution!


  • 0
    T
    public class Solution {
        public int leastBricks(List<List<Integer>> wall) {
            if(wall==null || wall.size()<1) return 0;
            
            
            Map<Integer,Integer> map=new HashMap<>();
            
            int max=Integer.MIN_VALUE;
            
            for(int i=0;i<wall.size();i++){
                int wid=0;
                for(int j=0;j<wall.get(i).size()-1;j++){
                     wid+=wall.get(i).get(j);
                     map.put(wid,map.getOrDefault(wid,0)+1);
                }
            }
            
            for(Integer key:map.keySet()){
                max=Math.max(max,map.get(key));
            }
            return max==Integer.MIN_VALUE?wall.size():wall.size()-max;
        }
    }
    
    

Log in to reply
 

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