mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-08 02:15:01 +08:00
20 lines
282 B
Go
20 lines
282 B
Go
package leetcode
|
|
|
|
func leastBricks(wall [][]int) int {
|
|
m := make(map[int]int)
|
|
for _, row := range wall {
|
|
sum := 0
|
|
for i := 0; i < len(row)-1; i++ {
|
|
sum += row[i]
|
|
m[sum]++
|
|
}
|
|
}
|
|
max := 0
|
|
for _, v := range m {
|
|
if v > max {
|
|
max = v
|
|
}
|
|
}
|
|
return len(wall) - max
|
|
}
|