LeetCode problem#1732
Find the Highest Altitude
Solved in 1 languageJava
Solution
16 lines
1class Solution {
2 public int largestAltitude(int[] gain) {
3 int sumSoFar = 0;
4 int highest = 0;
5
6 for (int i = 0; i < gain.length; i++) {
7 sumSoFar = sumSoFar + gain[i];
8
9 if (sumSoFar > highest) {
10 highest = sumSoFar;
11 }
12 }
13
14 return highest;
15 }
16}Want a walkthrough of this Java solution?
Get a step-by-step explanation of the idea behind the code.
Problem statements belong to LeetCode and are on leetcode.com. We're not affiliated with LeetCode.