Skip to content

Commit e6a61a9

Browse files
authored
Java & C++ Solution of Day 19 - June Challenge | Find the Highest Altitude
1 parent 702f437 commit e6a61a9

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public:
3+
int largestAltitude(vector<int>& gain) {
4+
int maxAltitude = 0;
5+
int currAltitude = 0;
6+
7+
for (int it : gain) {
8+
currAltitude += it;
9+
maxAltitude = max(maxAltitude, currAltitude);
10+
}
11+
12+
return maxAltitude;
13+
}
14+
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution {
2+
public int largestAltitude(int[] gain) {
3+
int maxAltitude = 0;
4+
int currAltitude = 0;
5+
6+
for (int it : gain) {
7+
currAltitude += it;
8+
maxAltitude = Math.max(maxAltitude, currAltitude);
9+
}
10+
11+
return maxAltitude;
12+
}
13+
}

0 commit comments

Comments
 (0)