some more problems

This commit is contained in:
2022-05-30 23:03:12 +01:00
parent e7b17e4450
commit 8181578c11
3 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
impl Solution {
pub fn max_profit(prices: Vec<i32>) -> i32 {
prices
.iter()
.fold((prices[0], 0), |(min, max_diff), &price| {
if price < min {
return (price, max_diff);
}
(min, max_diff.max(price - min))
}).1
}
}