File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ '''
2+ λ¬Έμ : μ΅λ λΆλΆ λ°°μ΄μ ν©μ ꡬνλ λ¬Έμ
3+ νμ΄:
4+ 1. λ°°μ΄μ λͺ¨λ μκ° μμμΈ κ²½μ°, κ°μ₯ ν° μλ₯Ό λ°ν
5+ 2. λ°°μ΄μ μ²μλΆν° μμκ° λμ¬ λκΉμ§ μΈλ±μ€λ₯Ό μ΄λ
6+ 3. μμκ° λμ¨ μ΄νλΆν°λ νμ¬ ν©μ΄ μμμΈ λμμ κ³μ λνκ³ , μμκ° λλ©΄ λ€μ μμλ₯Ό μ°Ύμ
7+ 4. λ§€ λ¨κ³λ§λ€ μ΅λ ν©μ κ°±μ
8+ μκ°λ³΅μ‘λ: O(n)
9+ λ°°μ΄μ ν λ² μννλ©° μ΅λ λΆλΆ λ°°μ΄μ ν©μ κ³μ°νλ―λ‘ μ 체 μκ°λ³΅μ‘λλ O(n)μ΄λ€.
10+ 곡κ°λ³΅μ‘λ: O(1)
11+ μΆκ°μ μΈ κ³΅κ°μ μ¬μ©νμ§ μμΌλ―λ‘ μ 체 곡κ°λ³΅μ‘λλ O(1)μ΄λ€.
12+ '''
13+
14+
15+ class Solution :
16+ def maxSubArray (self , nums : List [int ]) -> int :
17+ n = len (nums )
18+ answ = 0
19+ if max (nums ) <= 0 :
20+ return max (nums )
21+ i = 0
22+ while nums [i ] < 0 :
23+ i += 1
24+ now = 0
25+ while i < n :
26+ if now > 0 and i < n :
27+ now += nums [i ]
28+ i += 1
29+ else :
30+ while now <= 0 and i < n :
31+ now = nums [i ]
32+ i += 1
33+ answ = max (answ , now )
34+
35+ return answ
36+
You canβt perform that action at this time.
0 commit comments