diff --git a/maximum-product-subarray/DaleSeo.rs b/maximum-product-subarray/DaleSeo.rs new file mode 100644 index 0000000000..ac0097211f --- /dev/null +++ b/maximum-product-subarray/DaleSeo.rs @@ -0,0 +1,15 @@ +// TC: O(n) +// SC: O(1) +impl Solution { + pub fn max_product(nums: Vec) -> 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 + } +}