[LeetCode][Python3] 152. Maximum Product Subarray
2019. 4. 22. 23:39 |
프로그래밍/LeetCode
Problem :
https://leetcode.com/problems/maximum-product-subarray/
My Solution :
class Solution:
def maxProduct(self, nums: List[int]) -> int:
ans = pos = neg = nums[0]
for n in nums[1:]:
if n < 0:
pos, neg = n*neg, min(n*pos, n)
else:
pos, neg = max(n*pos, n), n*neg
ans = max(ans, pos)
return ans
'프로그래밍 > LeetCode' 카테고리의 다른 글
[LeetCode][Python3] 140. Word Break II (0) | 2019.04.25 |
---|---|
[LeetCode][Python3] 50. Pow(x, n) (0) | 2019.04.24 |
[LeetCode][Python3] 212. Word Search II (0) | 2019.04.24 |
[LeetCode][Python3] 41. First Missing Positive (0) | 2019.04.23 |
[LeetCode][Python3] 124. Binary Tree Maximum Path Sum (0) | 2019.04.20 |
[LeetCode][Python3] 322. Coin Change (0) | 2019.04.20 |
[LeetCode][Python3] 54. Spiral Matrix (0) | 2019.04.18 |
[LeetCode][Python3] 76. Minimum Window Substring (0) | 2019.04.16 |
최근에 달린 댓글 최근에 달린 댓글