From 458069c9474596f8b08fcac7a58434a12f9720cc Mon Sep 17 00:00:00 2001 From: iamyoshita <35068136+iamyoshita@users.noreply.github.com> Date: Mon, 29 Aug 2022 17:02:15 -0400 Subject: [PATCH] optimized code to reduce runtime, faster than 98% There is no need to initialize res as max(nums[0]) because the loop takes care of that. --- python/152-Maximum-Product-Subarray.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/152-Maximum-Product-Subarray.py b/python/152-Maximum-Product-Subarray.py index 93f00e256..52d08d3d0 100644 --- a/python/152-Maximum-Product-Subarray.py +++ b/python/152-Maximum-Product-Subarray.py @@ -1,7 +1,7 @@ class Solution: def maxProduct(self, nums: List[int]) -> int: # O(n)/O(1) : Time/Memory - res = max(nums) + res = nums[0] curMin, curMax = 1, 1 for n in nums: