40 lines
515 B
Go
Executable File
40 lines
515 B
Go
Executable File
package main
|
|
|
|
import "fmt"
|
|
|
|
func minimumArea(grid [][]int) int {
|
|
row := len(grid)
|
|
col := len(grid[0])
|
|
|
|
min_x := col
|
|
max_x := 0
|
|
min_y := row
|
|
max_y := 0
|
|
|
|
for i:=0; i<row; i++{
|
|
for j:=0; j<col; j++{
|
|
if grid[i][j] == 1{
|
|
min_x = Min(min_x, j)
|
|
max_x = Max(max_x, j)
|
|
min_y = Min(min_y, i)
|
|
max_y = Max(max_y, i)
|
|
}
|
|
}
|
|
}
|
|
|
|
return (max_x-min_x+1) * (max_y-min_y+1)
|
|
}
|
|
|
|
func Min(a, b int)int{
|
|
if a < b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|
|
|
|
func Max(a, b int)int{
|
|
if a > b{
|
|
return a
|
|
}
|
|
return b
|
|
} |