[LeetCode]#1732. Find the Highest Altitude

Input: gain = [-5,1,5,0,-7]
Output: 1
Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.
  1. Initial ans[0]=0
  2. Calculate ans[n]+gain[n]
  3. Append ans[n+1]
  4. Return max(ans)
class Solution:
def largestAltitude(self, gain):
ans=[]
ans.append(0)
for i in range(0,len(gain)):
tmp=ans[i]+gain[i]
ans.append(tmp)

return max(ans)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store