일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Protocol
- 715. Range Module
- concurrency
- iterator
- attribute
- kaggle
- 109. Convert Sorted List to Binary Search Tree
- Convert Sorted List to Binary Search Tree
- LeetCode
- 43. Multiply Strings
- Substring with Concatenation of All Words
- Decorator
- 파이썬
- 운영체제
- 프로그래머스
- Python
- data science
- 컴퓨터의 구조
- 시바견
- Python Implementation
- DWG
- shiba
- t1
- Class
- Python Code
- Regular Expression
- Generator
- 30. Substring with Concatenation of All Words
- 밴픽
- 315. Count of Smaller Numbers After Self
Archives
- Today
- Total
Scribbling
LeetCode: 152. Maximum Product Subarray 본문
class Solution:
def maxProduct(self, nums: List[int]) -> int:
ret = -int(1e9)
prod = 1
for num in nums:
prod *= num
ret = max(ret, prod)
if num == 0:
prod = 1
prod = 1
for i in range(len(nums)-1, -1, -1):
prod *= nums[i]
ret = max(ret, prod)
if nums[i] == 0:
prod = 1
return ret
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 162. Find Peak Element (0) | 2021.12.01 |
---|---|
LeetCode: 155. Min Stack (0) | 2021.11.30 |
LeetCode: 134. Gas Station (0) | 2021.11.26 |
LeetCode: 150. Evaluate Reverse Polish Notation (0) | 2021.11.26 |
LeetCode: 238. Product of Array Except Self (0) | 2021.11.25 |