Leetcode Note: Go - Projection Area of 3d Shapes

Projection Area of 3D Shapes - LeetCode
https://leetcode.com/problems/projection-area-of-3d-shapes/

  • Go 言語で取り組んだメモ

回答

Projection Area of 3D Shapes - LeetCode
https://leetcode.com/problems/projection-area-of-3d-shapes/solution/

Golang solution with quick explanation and images - LeetCode Discuss
https://leetcode.com/problems/projection-area-of-3d-shapes/discuss/1194480/Golang-solution-with-quick-explanation-and-images

func projectionArea(grid [][]int) int {
	result := 0

	for i := 0; i < len(grid); i++ {
		maxRow, maxCol := 0, 0

		for j := 0; j < len(grid[i]); j++ {
			if grid[j][i] > maxRow {
				maxRow = grid[j][i]
			}
			if grid[i][j] > maxCol {
				maxCol = grid[i][j]
			}
			if grid[i][j] != 0 {
				result++
			}
		}
		result = result + maxCol + maxRow
	}

	return result
}