Skip to content

Commit 7124722

Browse files
authored
Added solution for 1732
1 parent 9a0ebb8 commit 7124722

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

01732. Find the Highest Altitude.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use std::cmp;
2+
3+
impl Solution {
4+
// Keep re-calculating current altitude by adding the net gain. Keep track of the highest gain while calculating each gain
5+
pub fn largest_altitude(gain: Vec<i32>) -> i32 {
6+
let mut current_gain = 0;
7+
let mut highest_gain = 0;
8+
9+
for i in gain {
10+
current_gain += i;
11+
highest_gain = cmp::max(highest_gain, current_gain);
12+
}
13+
return highest_gain;
14+
}
15+
}

0 commit comments

Comments
 (0)