luoheng
10/11/2019 - 8:39 AM

projectionArea

func projectionArea(grid [][]int) int {
    col, row := len(grid), len(grid[0])
    maxX := make([]int, row)
    maxY := make([]int, col)
    sum := col * row
    for i := 0; i < col; i++ {
        for j := 0; j < row; j++ {
            if maxX[j] < grid[i][j] {
                maxX[j] = grid[i][j]
            }
            if maxY[i] < grid[i][j] {
                maxY[i] = grid[i][j]
            }
            if grid[i][j] == 0 {
                sum--
            }
        }
    }
    for _, m := range maxX {
        sum += m
    }
    for _, m := range maxY {
        sum += m
    }
    return sum
}