Skip to content

Commit c766769

Browse files
authored
Create find-the-highest-altitude.cpp
1 parent 0c02ac1 commit c766769

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

C++/find-the-highest-altitude.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
int largestAltitude(vector<int>& gain) {
7+
int result = 0, curr = 0;
8+
for (const auto& g : gain) {
9+
curr += g;
10+
result = max(result, curr);
11+
}
12+
return result;
13+
}
14+
};

0 commit comments

Comments
 (0)