Skip to content

Commit 02e98dc

Browse files
committed
p1800
1 parent 91f417a commit 02e98dc

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
mod p2948;
1+
mod p1800;
22

33
pub fn main() {
4-
p2948::run();
4+
p1800::run();
55
}

src/p1800.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
pub fn run() {
2+
for i in [
3+
4+
] {
5+
println!("{}", max_ascending_sum(i));
6+
}
7+
}
8+
9+
pub fn max_ascending_sum(nums: Vec<i32>) -> i32 {
10+
let mut nums = nums.into_iter();
11+
let mut previous = nums.next().unwrap();
12+
13+
let mut highest = previous;
14+
let mut current = previous;
15+
16+
while let Some(n) = nums.next() {
17+
if previous >= n {
18+
current = 0;
19+
}
20+
21+
current += n;
22+
23+
highest = highest.max(current);
24+
25+
previous = n;
26+
}
27+
28+
highest
29+
}

0 commit comments

Comments
 (0)