55- The product of any subarray of nums is guaranteed to fit in a 32-bit integer.
66
77Time Complexity: O(n)
8- - λ°°μ΄μ ν λ²λ§ μννλ©΄μ κ° μμΉμμ μμ μκ° μ°μ°λ§ μν
8+ - λ°°μ΄μ ν λ²λ§ μννκ³ , κ° μμΉμμ μμ μκ° μ°μ°(max, min, κ³±μ
)λ§ μν
99
1010Space Complexity: O(1)
11- - κ³ μ λ μΆκ° λ³μλ§ μ¬μ© (curr_max, curr_min, ...)
11+ - μ
λ ₯ ν¬κΈ°μ 무κ΄νκ² κ³ μ λ λ³μ (curr_max, curr_min, result, temp)λ§ μ¬μ©
1212
1313νμ΄λ°©λ²:
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])
17174. λ§€ λ¨κ³λ§λ€ result μ
λ°μ΄νΈ
1818
1919κ³ λ €μ¬ν:
20- 1. κ°μ΄ 0μΈ κ²½μ° β μλ‘ μμν΄μΌ ν¨
21- 2. temp λ³μ: curr_maxλ₯Ό μ
λ°μ΄νΈνλ©΄ curr_min κ³μ° μ μλ κ°μ΄ νμν¨
20+ 1. κ°μ΄ 0μΈ κ²½μ° μλ‘ μμν΄μΌ ν¨
21+ 2. temp λ³μ: curr_min κ³μ° μ curr_maxλ₯Ό μ
λ°μ΄νΈνκΈ° μ μ κ°μ΄ νμν¨
2222"""
2323class Solution :
2424 def maxProduct (self , nums : List [int ]) -> int :
@@ -33,4 +33,3 @@ def maxProduct(self, nums: List[int]) -> int:
3333 result = max (result , curr_max )
3434
3535 return result
36-
0 commit comments