Leetcode Note: Go - Range Addition II

Range Addition II - LeetCode https://leetcode.com/problems/range-addition-ii/

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

所感

  • マス目の計算

回答

Golang fast - LeetCode Discuss https://leetcode.com/problems/range-addition-ii/discuss/563153/Golang-fast

func maxCount(m int, n int, ops [][]int) int {
	area := []int{m, n}
	for _, op := range ops {
		intersection(area, op)
	}
	return area[0] * area[1]
}

func intersection(a, b []int) {
	a[0] = min(a[0], b[0])
	a[1] = min(a[1], b[1])
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}