We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a075497 commit 0b0ad1bCopy full SHA for 0b0ad1b
1 file changed
maximum-product-subarray/Seoya0512.py
@@ -0,0 +1,19 @@
1
+'''
2
+이전 곱을 저장해서 곱셈 연산을 줄이는 방식
3
+해당 연산 방식은 Time Limited Exceeded 오류를 발생했습니다.
4
+
5
+시간 복잡도: O(n^2)
6
+- 외부 for-loop과 내부 for-loop이 각각 n번씩 실행되기 때문
7
+공간 복잡도: O(1)
8
9
+class Solution:
10
+ def maxProduct(self, nums: List[int]) -> int:
11
+ max_product = nums[0]
12
13
+ for i in range(len(nums)):
14
+ prev = 1
15
+ for j in range(i, len(nums)):
16
+ prev = prev * nums[j]
17
+ max_product = max(max_product, prev)
18
19
+ return max_product
0 commit comments