Leetcode Note: Go - Find the Highest Altitude

Find the Highest Altitude - LeetCode
https://leetcode.com/problems/find-the-highest-altitude/

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

回答

Golang-solution - Find the Highest Altitude - LeetCode
https://leetcode.com/problems/find-the-highest-altitude/solutions/1078389/golang-solution/

func largestAltitude(gain []int) int {
	var max, alt int
	for _, g := range gain {
		alt += g
		if alt > max {
			max = alt
		}
	}
	return max
}