#1732

Find the Highest Altitude

newbie · 145 · lc easy +13 · verified · 83.9% accepted · 3,237 likes · top 95%

Description

A biker's trip spans n + 1 points beginning at altitude 0. You are given gain of length n where gain[i] is the net altitude change between point i and i + 1. Return the highest altitude reached at any point.

Example 1:

Input: gain = [-5,1,5,0,-7]
Output: 1
Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.

Example 2:

Input: gain = [-4,-3,-2,-1,4,3,2]
Output: 0
Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.

Code

1
2
3