File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ [๋ฌธ์ ํ์ด]
3
+ - ์ฃผ์ด์ง ๋ฐฐ์ด์์ ์ฐ์๋ ์ ๋ฐฐ์ด์ ํฉ์ด ํฐ ์ ๊ตฌํ๊ธฐ
4
+ - (1) ํ์ฌ์์ ํ์ฌ๊น์ง์ ํฉ ์ค ํฐ ์ ๊ตฌํ๊ธฐ : ํ์ฌ ์ธ๋ฑ์ค๋ถํฐ ์์๋๊ฑฐ๋, ํ์ฌ ์ธ๋ฑ์ค๊น์ง ๋ํด์ง ๊ฒ
5
+ - (2) ์ต๋๊ฐ๊ณผ (1)๋ฒ ์ ์ค ํฐ ์ ๊ตฌํ๊ธฐ
6
+ time: O(N), space: O(1)
7
+
8
+ [ํ๊ณ ]
9
+ ์๋ฃจ์
๊น์ง๋ ๊ทผ์ ํ๋๋ฐ, ๊ฒฐ๊ตญ ํด๊ฒฐ์ ์๊พธ ์๋๋ค..
10
+ ์ด๋ป๊ฒ ์ ๊ทผํด์ผ ์๋ฃจ์
๊น์ง ๋๋ฌ ํ ์ ์์๊น..
11
+ */
12
+ class Solution {
13
+ public int maxSubArray (int [] nums ) {
14
+ int max = nums [0 ];
15
+ int sum = nums [0 ];
16
+ for (int i = 1 ; i < nums .length ; i ++) {
17
+ sum = Math .max (nums [i ], sum + nums [i ]);
18
+ max = Math .max (max , sum );
19
+ }
20
+ return max ;
21
+ }
22
+ }
23
+
You canโt perform that action at this time.
0 commit comments