We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 58e8a5e commit b963930Copy full SHA for b963930
scripts/algorithms/F/Find the Highest Altitude/Find the Highest Altitude.cpp
@@ -1,14 +1,16 @@
1
+// Runtime: 4 ms (Top 37.21%) | Memory: 8.30 MB (Top 69.02%)
2
+
3
class Solution {
4
public:
5
int largestAltitude(vector<int>& gain) {
- int max_alt=0;
- 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);
+ int maxAltitude = 0;
+ int currentAltitude = 0;
9
+ for (int i = 0; i < gain.size(); i++) {
10
+ currentAltitude += gain[i];
11
+ maxAltitude = max(maxAltitude, currentAltitude);
12
}
- return max_alt;
13
14
+ return maxAltitude;
15
16
};
-
-//TC: O(n), SC: O(1)
0 commit comments