1732. Find the Highest Altitude
/**
* Problem: LeetCode 1732 - Find the Highest Altitude
* Difficulty: Easy
* Language: Java
* Author: CodeByTushu
*/
class Solution {
public int largestAltitude(int[] gain) {
int altitude = 0;
int maxAltitude = 0;
for (int g : gain) {
altitude += g;
maxAltitude = Math.max(maxAltitude, altitude);
}
return maxAltitude;
}
}
"""
Problem: LeetCode 1732 - Find the Highest Altitude
Difficulty: Easy
Language: Python
Author: CodeByTushu
"""
from typing import List
class Solution:
def largestAltitude(self, gain: List[int]) -> int:
altitude = 0
max_altitude = 0
for g in gain:
altitude += g
max_altitude = max(max_altitude, altitude)
return max_altitude
/**
* Problem: LeetCode 1732 - Find the Highest Altitude
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
#include <vector>
#include <algorithm>
using namespace std;
/**
* Problem: LeetCode 1732 - Find the Highest Altitude
* Difficulty: Easy
* Language: C++
* Author: CodeByTushu
*/
class Solution {
public:
int largestAltitude(vector<int>& gain) {
int altitude = 0;
int maxAltitude = 0;
for (int g : gain) {
altitude += g;
maxAltitude = max(maxAltitude, altitude);
}
return maxAltitude;
}
};
/**
* Problem: LeetCode 1732 - Find the Highest Altitude
* Difficulty: Easy
* Language: JavaScript
* Author: CodeByTushu
*/
var largestAltitude = function(gain) {
let altitude = 0;
let maxAltitude = 0;
for (const g of gain) {
altitude += g;
maxAltitude = Math.max(maxAltitude, altitude);
}
return maxAltitude;
};