File tree Expand file tree Collapse file tree 1 file changed +37
-4
lines changed Expand file tree Collapse file tree 1 file changed +37
-4
lines changed Original file line number Diff line number Diff line change 1
1
"""
2
2
[๋ฌธ์ ํ์ด]
3
3
# Inputs
4
-
4
+ - ์ ์ํ nums
5
5
# Outputs
6
-
6
+ - ๋ถ๋ถ ๋ฐฐ์ด ์ค ํฉ์ด ๊ฐ์ฅ ํฐ ๋ฐฐ์ด์ ํฉ
7
7
# Constraints
8
-
8
+ - 1 <= nums.length <= 10^5
9
+ - 10^4 <= nums[i] <= 10^4
9
10
# Ideas
11
+ ๊ฐ์ฅ ํฐ ํฉ์ ๊ตฌํ๋ ๋ฐฉ๋ฒ
12
+ ์ ๋ ฌ์ ๋น์ฐํ X
13
+ 10^5๊ฐ ์ต๋๋ผ O(n) ๊ณ ๋ ค ํ์
14
+ -2 1 -3 4 -1 2 1 -5 4
15
+ l, r = 0, 0 -> ์์ง์ด๋ฉด์
16
+ r = 1
17
+ -2 < 1 -> -1
18
+
19
+ -2 -1 -4 0 -1 1 2 -3 1
20
+ 1. ๋์ ํฉ?
21
+
22
+ -2 1 -2 4 3 5 6 1 5
23
+
24
+ 5 4 -1 7 8
25
+ 5 9 8 15 23
26
+
27
+ ์ง๊ธ๊น์ง์ ํฉ ๋ณด๋ค ๋ค์ ์์๊ฐ ํฌ๋ฉด ๊ทธ๋๋ก ๋๊ณ , ์๋๋ฉด ํฉ์ผ๋ก ๋์ฒด
28
+ => TC: O(n), SC: O(1)
10
29
11
30
[ํ๊ณ ]
31
+ ๋จผ๊ฐ..๋๋ ค ๋ง์ถ ๋๋์ด๋ผ ํด์ค ์ฐธ๊ณ
32
+ ->
33
+ """
34
+
35
+ class Solution :
36
+ def maxSubArray (self , nums : List [int ]) -> int :
37
+ if len (nums ) == 1 :
38
+ return nums [0 ]
39
+
40
+ memo = nums [0 ]
41
+
42
+ for i in range (1 , len (nums )):
43
+ if nums [i ] < nums [i - 1 ] + nums [i ]:
44
+ nums [i ] += nums [i - 1 ]
12
45
13
- """
46
+ return max ( nums )
You canโt perform that action at this time.
0 commit comments