Update 0121.买卖股票的最佳时机.md about rust

This commit is contained in:
fwqaaq
2023-06-03 13:58:57 +08:00
committed by GitHub
parent 4ab224b30d
commit 2d66c713f0

View File

@ -510,7 +510,22 @@ public class Solution
} }
``` ```
Rust:
> 贪心
```rust
impl Solution {
pub fn max_profit(prices: Vec<i32>) -> i32 {
let (mut low, mut res) = (i32::MAX, 0);
for p in prices {
low = p.min(low);
res = res.max(p - low);
}
res
}
}
```
<p align="center"> <p align="center">