Skip to content

Commit b963930

Browse files
committed
Runtime: 4 ms (Top 37.21%) | Memory: 8.30 MB (Top 69.02%)
1 parent 58e8a5e commit b963930

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

scripts/algorithms/F/Find the Highest Altitude/Find the Highest Altitude.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
// Runtime: 4 ms (Top 37.21%) | Memory: 8.30 MB (Top 69.02%)
2+
13
class Solution {
24
public:
35
int largestAltitude(vector<int>& gain) {
4-
int max_alt=0;
5-
int curr_alt=0;
6-
for(int i=0;i<gain.size();i++){
7-
curr_alt+=gain[i];
8-
max_alt=max(curr_alt, max_alt);
6+
int maxAltitude = 0;
7+
int currentAltitude = 0;
8+
9+
for (int i = 0; i < gain.size(); i++) {
10+
currentAltitude += gain[i];
11+
maxAltitude = max(maxAltitude, currentAltitude);
912
}
10-
return max_alt;
13+
14+
return maxAltitude;
1115
}
1216
};
13-
14-
//TC: O(n), SC: O(1)

0 commit comments

Comments
 (0)