Skip to main content

1732. Find the Highest Altitude

https://leetcode.com/problems/find-the-highest-altitude

Python

class Solution:
def largestAltitude(self, gain: List[int]) -> int:
current, highest = 0, 0
for g in gain:
current = current + g
highest = max(highest, current)
return highest

Go

func largestAltitude(gain []int) int {
highest := 0
current := 0

for _, elm := range gain {
current += elm
if current > highest {
highest = current
}
}
return highest
}