1732. Find the Highest Altitude Easy

@problem@discussion
#Array#Prefix Sum



1/**
2 * [1732] Find the Highest Altitude
3 *
4 * There is a biker going on a road trip. The road trip consists of n + 1 points at different altitudes. The biker starts his trip on point 0 with altitude equal 0.
5 * You are given an integer array gain of length n where gain[i] is the net gain in altitude between points i​​​​​​ and i + 1 for all (0 <= i < n). Return the highest altitude of a point.
6 *  
7 * Example 1:
8 * 
9 * Input: gain = [-5,1,5,0,-7]
10 * Output: 1
11 * Explanation: The altitudes are [0,-5,-4,1,1,-6]. The highest is 1.
12 * 
13 * Example 2:
14 * 
15 * Input: gain = [-4,-3,-2,-1,4,3,2]
16 * Output: 0
17 * Explanation: The altitudes are [0,-4,-7,-9,-10,-6,-3,-1]. The highest is 0.
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	n == gain.length
23 * 	1 <= n <= 100
24 * 	-100 <= gain[i] <= 100
25 * 
26 */
27pub struct Solution {}
28
29// problem: https://leetcode.com/problems/find-the-highest-altitude/
30// discuss: https://leetcode.com/problems/find-the-highest-altitude/discuss/?currentPage=1&orderBy=most_votes&query=
31
32// submission codes start here
33
34impl Solution {
35    pub fn largest_altitude(gain: Vec<i32>) -> i32 {
36        0
37    }
38}
39
40// submission codes end
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn test_1732() {
48    }
49}
50


Back
© 2025 bowen.ge All Rights Reserved.