Leetcode / 1732. Find the Highest Altitude
Pick a programming language:
Here is the source code for the solution to this problem.
class Solution {
public int largestAltitude(int[] gain) {
int sumSoFar = 0;
int highest = 0;
for (int i = 0; i < gain.length; i++) {
sumSoFar = sumSoFar + gain[i];
if (sumSoFar > highest) {
highest = sumSoFar;
}
}
return highest;
}
}
Did you like the lesson? 😆👍
Consider a donation to support our work: