1732_FindtheHighestAltitude - a920604a/leetcode GitHub Wiki
categories: leetcode comments: false tags:
- Prefix Sum title: 1732. Find the Highest Altitude
class Solution {
public:
int largestAltitude(vector<int>& gain) {
int mx_height = 0;
int cur_height = 0;
for(int g:gain){
cur_height += g;
mx_height = max(mx_height, cur_height);
}
return mx_height;
}
};
- time complexity
O(n)
- space complexity
O(1)