Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions maximum-product-subarray/DaleSeo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// TC: O(n)
// SC: O(1)
impl Solution {
pub fn max_product(nums: Vec<i32>) -> i32 {
let mut ans = nums[0];
let (mut max, mut min) = (1, 1);
for num in nums {
let candidates = [max * num, min * num, num];
max = *candidates.iter().max().unwrap();
min = *candidates.iter().min().unwrap();
ans = ans.max(max);
}
ans
}
}
Loading