some more problems
This commit is contained in:
12
best-time-to-buy-and-sell-stock/sol.rs
Normal file
12
best-time-to-buy-and-sell-stock/sol.rs
Normal 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user