5
5
- The product of any subarray of nums is guaranteed to fit in a 32-bit integer.
6
6
7
7
Time Complexity: O(n)
8
- - λ°°μ΄μ ν λ²λ§ μννλ©΄μ κ° μμΉμμ μμ μκ° μ°μ°λ§ μν
8
+ - λ°°μ΄μ ν λ²λ§ μννκ³ , κ° μμΉμμ μμ μκ° μ°μ°(max, min, κ³±μ
)λ§ μν
9
9
10
10
Space Complexity: O(1)
11
- - κ³ μ λ μΆκ° λ³μλ§ μ¬μ© (curr_max, curr_min, ...)
11
+ - μ
λ ₯ ν¬κΈ°μ 무κ΄νκ² κ³ μ λ λ³μ (curr_max, curr_min, result, temp)λ§ μ¬μ©
12
12
13
13
νμ΄λ°©λ²:
14
- 1. DPλ‘ κ° μμΉμμ κ°λ₯ν μ΅λκ³±κ³Ό μ΅μκ³±μ λμμ μΆμ ν¨
15
- 2. κ° μμΉμμ μΈ κ°μ μ νμ§ μ‘΄μ¬: μλ‘ μμ vs μ΄μ μ΅λκ³±κ³Ό κ³±νκΈ° vs μ΄μ μ΅μκ³±κ³Ό κ³±νκΈ°
16
- 3. μ΅μκ³±μ΄ νμν μ΄μ : λμ€μ μμλ₯Ό λ§λ¬μ λ μ΅λκ°μ΄ λ μ μκΈ° λλ¬Έ
14
+ 1. DPλ‘ κ° μμΉμμ κ°λ₯ν μ΅λκ°κ³Ό μ΅μκ°μ ν¨κ» μ
λ°μ΄νΈν¨
15
+ 2. κ° μμΉμμ μΈ κ°μ μ νμ§ μ‘΄μ¬: μλ‘ μμ vs μ΄μ μ΅λκ°κ³Ό κ³±νκΈ° vs μ΄μ μ΅μκ°κ³Ό κ³±νκΈ°
16
+ 3. μ΅μκ°μ κ³μ μ
λ°μ΄νΈ νλ μ΄μ : μμ*μμ = μλ‘μ΄ μ΅λκ°, curr_max μ
λ°μ΄νΈν λ μ°μ (μμ: nums = [2, 3, -2, 4, -1])
17
17
4. λ§€ λ¨κ³λ§λ€ result μ
λ°μ΄νΈ
18
18
19
19
κ³ λ €μ¬ν:
20
- 1. κ°μ΄ 0μΈ κ²½μ° β μλ‘ μμν΄μΌ ν¨
21
- 2. temp λ³μ: curr_maxλ₯Ό μ
λ°μ΄νΈνλ©΄ curr_min κ³μ° μ μλ κ°μ΄ νμν¨
20
+ 1. κ°μ΄ 0μΈ κ²½μ° μλ‘ μμν΄μΌ ν¨
21
+ 2. temp λ³μ: curr_min κ³μ° μ curr_maxλ₯Ό μ
λ°μ΄νΈνκΈ° μ μ κ°μ΄ νμν¨
22
22
"""
23
23
class Solution :
24
24
def maxProduct (self , nums : List [int ]) -> int :
@@ -33,4 +33,3 @@ def maxProduct(self, nums: List[int]) -> int:
33
33
result = max (result , curr_max )
34
34
35
35
return result
36
-
0 commit comments