mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
Update 0121.买卖股票的最佳时机.md about rust
This commit is contained in:
@ -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">
|
||||||
|
Reference in New Issue
Block a user