Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 2x 2x 2x 9x 13x 13x 13x 2x | export default function leastBricks(wall: number[][]): number {
// 竖线穿过最多的缝隙
const gapMap = new Map<number, number>()
let maxGap = 0
for (const row of wall) {
for (let i = 0, offset = 0; i < row.length - 1; i++) {
offset += row[i]
gapMap.set(offset, (gapMap.get(offset) ?? 0) + 1)
maxGap = Math.max(maxGap, gapMap.get(offset) as number)
}
}
return wall.length - maxGap
}
|