Skip to content

Commit b8f32ef

Browse files
committed
first commit
0 parents  commit b8f32ef

424 files changed

Lines changed: 54617 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

โ€Ž.gitignoreโ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

โ€Ž2-python/ch06/1-1.pyโ€Ž

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
strs = []
4+
for char in s:
5+
if char.isalnum():
6+
strs.append(char.lower())
7+
8+
# ํŒฐ๋ฆฐ๋“œ๋กฌ ์—ฌ๋ถ€ ํŒ๋ณ„
9+
while len(strs) > 1:
10+
if strs.pop(0) != strs.pop():
11+
return False
12+
13+
return True

โ€Ž2-python/ch06/1-2.pyโ€Ž

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import collections
2+
from typing import Deque
3+
4+
5+
class Solution:
6+
def isPalindrome(self, s: str) -> bool:
7+
# ์ž๋ฃŒํ˜• ๋ฐํฌ๋กœ ์„ ์–ธ
8+
strs: Deque = collections.deque()
9+
10+
for char in s:
11+
if char.isalnum():
12+
strs.append(char.lower())
13+
14+
while len(strs) > 1:
15+
if strs.popleft() != strs.pop():
16+
return False
17+
18+
return True

โ€Ž2-python/ch06/1-3.pyโ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import re
2+
3+
4+
class Solution:
5+
def isPalindrome(self, s: str) -> bool:
6+
s = s.lower()
7+
# ์ •๊ทœ์‹์œผ๋กœ ๋ถˆํ•„์š”ํ•œ ๋ฌธ์ž ํ•„ํ„ฐ๋ง
8+
s = re.sub('[^a-z0-9]', '', s)
9+
10+
return s == s[::-1] # ์Šฌ๋ผ์ด์‹ฑ

โ€Ž2-python/ch06/1-4.cโ€Ž

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// C
2+
bool isPalindrome(char *s) {
3+
int bias_left = 0;
4+
int bias_right = 1;
5+
6+
int str_len = strlen(s);
7+
for (int i = 0; i < str_len; i++) {
8+
// ์Šคํ‚ต ํฌ์ธํ„ฐ ์ฒ˜๋ฆฌ
9+
while (!isalnum(s[i + bias_left])) {
10+
bias_left++;
11+
if (i + bias_left == str_len)
12+
return true;
13+
}
14+
while (!isalnum(s[str_len - i - bias_right])) {
15+
bias_right++;
16+
}
17+
18+
if (i + bias_left >= str_len - i - bias_right)
19+
break;
20+
// ํŒฐ๋ฆฐ๋“œ๋กฌ ๋น„๊ต
21+
if (tolower(s[i + bias_left]) != tolower(s[str_len - i - bias_right]))
22+
return false;
23+
}
24+
return true;
25+
}

โ€Ž2-python/ch06/2-1.pyโ€Ž

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def reverseString(self, s: List[str]) -> None:
6+
left, right = 0, len(s) - 1
7+
while left < right:
8+
s[left], s[right] = s[right], s[left]
9+
left += 1
10+
right -= 1

โ€Ž2-python/ch06/2-2.pyโ€Ž

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def reverseString(self, s: List[str]) -> None:
6+
s.reverse()

โ€Ž2-python/ch06/3-1.pyโ€Ž

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def reorderLogFiles(self, logs: List[str]) -> List[str]:
6+
letters, digits = [], []
7+
for log in logs:
8+
if log.split()[1].isdigit():
9+
digits.append(log)
10+
else:
11+
letters.append(log)
12+
13+
# ๋‘ ๊ฐœ์˜ ํ‚ค๋ฅผ ๋žŒ๋‹ค ํ‘œํ˜„์‹์œผ๋กœ ์ •๋ ฌ
14+
letters.sort(key=lambda x: (x.split()[1:], x.split()[0]))
15+
return letters + digits

โ€Ž2-python/ch06/4-1.pyโ€Ž

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import collections
2+
import re
3+
from typing import List
4+
5+
6+
class Solution:
7+
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
8+
words = [word for word in re.sub(r'[^\w]', ' ', paragraph)
9+
.lower().split()
10+
if word not in banned]
11+
12+
counts = collections.Counter(words)
13+
# ๊ฐ€์žฅ ํ”ํ•˜๊ฒŒ ๋“ฑ์žฅํ•˜๋Š” ๋‹จ์–ด์˜ ์ฒซ ๋ฒˆ์งธ ์ธ๋ฑ์Šค ๋ฆฌํ„ด
14+
return counts.most_common(1)[0][0]

โ€Ž2-python/ch06/5-1.pyโ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import collections
2+
from typing import List
3+
4+
5+
class Solution:
6+
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
7+
anagrams = collections.defaultdict(list)
8+
9+
for word in strs:
10+
# ์ •๋ ฌํ•˜์—ฌ ๋”•์…”๋„ˆ๋ฆฌ์— ์ถ”๊ฐ€
11+
anagrams[''.join(sorted(word))].append(word)
12+
return list(anagrams.values())

0 commit comments

Comments
ย (0)