Skip to content

Commit 55edeb5

Browse files
author
zim0369
committed
Create 152-Maximum-Product-Subarray.rs
1 parent 939af48 commit 55edeb5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
impl Solution {
2+
pub fn max_product(nums: Vec<i32>) -> i32 {
3+
let (mut res, mut big, mut small) = (*nums.iter().max().unwrap(), 1, 1);
4+
for n in nums {
5+
let tmp = big;
6+
big = vec![n, big * n, small * n].into_iter().max().unwrap();
7+
small = vec![n, tmp * n, small * n].into_iter().min().unwrap();
8+
res = res.max(big);
9+
}
10+
res
11+
}
12+
}

0 commit comments

Comments
 (0)