2025-09-22 22:13
Status: adult
Tags: leetcode leetcode-easy google strings Leetcode
Find the Highest Altitude
Code
class Solution(object):
def largestAltitude(self, gain):
"""
:type gain: List[int]
:rtype: int
"""
'''
0 - 1: -5
1 - 2: 1
2 - 3: 5
3 - 4: 0
4 - 5: -7
'''
max_height, cur_height = 0, 0
for g in gain:
cur_height += g
max_height = max(max_height, cur_height)
return max_height
Explanation
- We need to keep track of the current height, and max height
- Iterate through the array, calculate current height, and set max height equal to the max between max height and cur height
- Return max height
References
Me