Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 458069c

Browse files
authored
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.
1 parent b25d73e commit 458069c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

python/152-Maximum-Product-Subarray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class Solution:
22
def maxProduct(self, nums: List[int]) -> int:
33
# O(n)/O(1) : Time/Memory
4-
res = max(nums)
4+
res = nums[0]
55
curMin, curMax = 1, 1
66

77
for n in nums:

0 commit comments

Comments
 (0)