MCPcopy Create free account
hub / github.com/HuberTRoy/leetCode / Solution

Class Solution

Array/MaximumProductSubarray.py:48–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46"""
47
48class Solution(object):
49 def maxProduct(self, nums):
50 """
51 :type nums: List[int]
52 :rtype: int
53 """
54
55 maxes = nums[0]
56 currentNums = [[nums[0]]]
57
58 for i in range(1, len(nums)):
59 x = nums[i]
60 temp = [x*j for j in currentNums[i-1]]
61
62 minx = min(x, min(temp))
63 maxx = max(x, max(temp))
64
65 currentNums.append([minx, maxx])
66 maxes = max(maxes, maxx)
67
68 return maxes
69
70 # maxes = nums[0]
71 # currentNums = [[nums[0]]]
72
73# for i in nums[1:]:
74# if not currentNums:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected