Leetcode 1732. Find the Highest Altitude

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Find the Highest Altitude

2. Solution

  • Version 1
1
2
3
4
5
6
7
8
class Solution:
def largestAltitude(self, gain: List[int]) -> int:
highest = 0
altitude = 0
for x in gain:
altitude += x
highest = max(highest, altitude)
return highest

Reference

  1. https://leetcode.com/problems/find-the-highest-altitude/
如果有收获,可以请我喝杯咖啡!