Skip to content

Files

Latest commit

 

History

History
28 lines (25 loc) · 868 Bytes

0554. Brick Wall.md

File metadata and controls

28 lines (25 loc) · 868 Bytes
Screen Shot 2023-05-28 at 3 39 33 AM Screen Shot 2023-05-28 at 3 39 43 AM
/**
 * @param {number[][]} wall
 * @return {number}
 */
var leastBricks = function(wall) {
    let count = 0;
    let map = new Map();

    for(let arr of wall) {
        let gap = 0;
        for(let i = 0; i < arr.length - 1; i++) {
            gap += arr[i];
            if(map.has(gap)) {
                map.set(gap, map.get(gap) + 1);
            } else {
                map.set(gap, 1);
            }
            count = Math.max(count, map.get(gap));
        }
    }
    return wall.length - count;
};