File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 1ms
3+ * Time Complexity: O(n)
4+ *
5+ * Memory: 76.88MB
6+ * Space Complexity: O(1)
7+ *
8+ * Approach: ์นด๋ฐ์ธ ์๊ณ ๋ฆฌ์ฆ
9+ * - ๋ถ๋ถ ๋ฐฐ์ด์ ํฉ์ด ์ต๋๊ฐ ๋๋ ๊ฐ์ ์ฐพ๋ ์๊ณ ๋ฆฌ์ฆ
10+ * 1) ์ด์ ํฉ๋ณด๋ค ํ์ฌ ์ซ์๊ฐ ๋ ํฌ๋ฉด ํ์ฌ ์ซ์๋ก sum์ ์ด๊ธฐํ
11+ */
12+ class Solution {
13+ public int maxSubArray (int [] nums ) {
14+ int sum = nums [0 ];
15+ int max = nums [0 ];
16+
17+ for (int i =1 ; i <nums .length ; i ++) {
18+ sum = Math .max (nums [i ], sum +nums [i ]);
19+ max = Math .max (max , sum );
20+ }
21+
22+ return max ;
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 0ms
3+ * Time Complexity: O(log n)
4+ * - n์ 2๋ก ๋๋๋ ๊ณผ์ ์ ๋ฐ๋ณตํ๋ฏ๋ก log n์ ๋น๋ก
5+ *
6+ * Memory: 42.32MB
7+ * Space Complexity: O(1)
8+ *
9+ * Approach: ๋นํธ ์ฐ์ฐ (๋๋์
๋ฐฉ์)
10+ * 1) n์ 2๋ก ๋๋ ๋๋จธ์ง(n%2)๋ฅผ ํ์ธํ์ฌ 1์ ๊ฐ์๋ฅผ ์นด์ดํธ
11+ * 2) ๋ง์ง๋ง์ 1์ ๋ฌด์กฐ๊ฑด ๋จ๊ธฐ ๋๋ฌธ์ while๋ฌธ ์ข
๋ฃ ํ 1์ ๋ํด์ค
12+ */
13+ class Solution {
14+ public int hammingWeight (int n ) {
15+ int count = 0 ;
16+ while (n > 1 ) {
17+ count += n %2 ;
18+ n /= 2 ;
19+ }
20+
21+ return count +1 ;
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ /**
2+ * Runtime: 2ms
3+ * Time Complexity: O(n)
4+ *
5+ * Memory: 44.29MB
6+ * Space Complexity: O(1)
7+ *
8+ * Approach: ํฌ ํฌ์ธํฐ
9+ * 1) ๋ฌธ์์ด์ ์ ๋์์๋ถํฐ ์์ํ๋ ๋ ํฌ์ธํฐ๋ฅผ ์ค์
10+ * 2) ํฌ์ธํฐ๊ฐ ๊ฐ๋ฆฌํค๋ ๋ฌธ์๊ฐ ์์ซ์๊ฐ ์๋ ๊ฒฝ์ฐ, ํด๋น ํฌ์ธํฐ๋ฅผ ์ด๋
11+ */
12+ class Solution {
13+ public boolean isPalindrome (String s ) {
14+ int start = 0 ;
15+ int end = s .length ()-1 ;
16+
17+ while (start < end ) {
18+ char currLeft = s .charAt (start );
19+ char currRight = s .charAt (end );
20+
21+ if (!Character .isLetterOrDigit (currLeft )) {
22+ start ++;
23+ } else if (!Character .isLetterOrDigit (currRight )) {
24+ end --;
25+ } else {
26+ if (Character .toLowerCase (currLeft ) != Character .toLowerCase (currRight )) {
27+ return false ;
28+ }
29+
30+ start ++;
31+ end --;
32+ }
33+ }
34+
35+ return true ;
36+ }
37+ }
You canโt perform that action at this time.
0 commit comments