lc-go/solutions/0/q85/solution.go
2026-01-13 00:14:04 +09:00

31 lines
528 B
Go

package q85
func maximalRectangle(matrix [][]byte) int {
var maxArea int
for row := range matrix {
for col := range matrix[0] {
matrix[row][col] -= '0'
if matrix[row][col] == 0 {
continue
}
if col > 0 {
matrix[row][col] += matrix[row][col-1]
}
maxW := matrix[row][col]
for i := 0; row-i >= 0; i++ {
if matrix[row-i][col] == 0 {
break
}
maxW = min(maxW, matrix[row-i][col])
maxArea = max(maxArea, int(maxW)*(i+1))
}
}
}
return maxArea
}
var _ = maximalRectangle