File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change
1
+ '''
2
+ μκ° λ³΅μ‘λ: O(n)
3
+ - 리μ€νΈλ₯Ό ν λ² μννλ©΄μ κ° μμμ λν΄ μ΅λκ°κ³Ό μ΅μκ°μ κ°±μ νλ―λ‘ O(n)μ
λλ€.
4
+
5
+ κ³΅κ° λ³΅μ‘λ: O(1)
6
+ - μΆκ°μ μΈ λ°°μ΄μ μ¬μ©νμ§ μκ³ , λͺ κ°μ λ³μλ§ μ¬μ©νλ―λ‘ O(1)μ
λλ€.
7
+ '''
8
+
9
+ from typing import List
10
+
11
+ class Solution :
12
+ def maxProduct (self , nums : List [int ]) -> int :
13
+ n = len (nums )
14
+ max_product = nums [0 ]
15
+ cur_max = nums [0 ] # νμ¬ μμΉκΉμ§ μ΅λ κ³±
16
+ cur_min = nums [0 ] # νμ¬ μμΉκΉμ§ μ΅μ κ³± (μμ λλΉ)
17
+
18
+ for i in range (1 , n ):
19
+ temp_max = cur_max
20
+ cur_max = max (nums [i ], cur_max * nums [i ], cur_min * nums [i ])
21
+ cur_min = min (nums [i ], temp_max * nums [i ], cur_min * nums [i ])
22
+ max_product = max (max_product , cur_max )
23
+
24
+ return max_product
You canβt perform that action at this time.
0 commit comments