Skip to content

Commit e2f022d

Browse files
committed
q121
1 parent ecd4a23 commit e2f022d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/dp/mod.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
mod q121;
2+
3+
4+
struct Solution ();
5+
impl Solution {
6+
pub fn max_profit(prices: Vec<i32>) -> i32 {
7+
8+
let mut max = 0;
9+
let mut min_item = prices[0];
10+
11+
12+
for x in prices.into_iter().skip(1) {
13+
min_item = min_item.min(x);
14+
max = max.max(x - min_item);
15+
16+
17+
}
18+
19+
20+
max
21+
}
22+
}
23+
24+
25+
26+
#[cfg(test)]
27+
mod tests {
28+
use super::*;
29+
30+
#[test] fn is_ok() {
31+
32+
assert_eq!(Solution::max_profit(vec![7,1,5,3,6,4]), 5)
33+
34+
35+
}
36+
}

src/dp/q121.rs

Whitespace-only changes.

0 commit comments

Comments
 (0)