Skip to content

Commit

Permalink
Treating Python String
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueimaginate committed Feb 23, 2021
1 parent e27f147 commit 248c757
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Coding Test/344.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Solution:
def reverseString(self, s: List[str]) -> None:
s.reverse()

7 changes: 7 additions & 0 deletions Coding Test/49.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Solution:
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
anagrams = collections.defaultdict(list)

for word in strs:
anagrams[''.join(sorted(word))].append(word)
return anagrams.values()
17 changes: 17 additions & 0 deletions Coding Test/5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution:
def longestPalindrome(self, s: str) -> str:
def expand(left: int, right: int) -> str:
while left >= 0 and right <= len(s) and s[left] == s[right-1]:
left -= 1
right += 1
return s[left+1:right-1]

if len(s) < 2 or s == s[::-1]:
return s

result = ''

for i in range(len(s)-1):
result = max(result, expand(i, i+1), expand(i, i+2), key=len)

return result
8 changes: 8 additions & 0 deletions Coding Test/819.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Solution:
def mostCommonWord(self, paragraph: str, banned: List[str]) -> str:
words = [word for word in re.sub('[^\w]', ' ', paragraph).lower().split() if word not in banned]

counts = collections.Counter(words)

return counts.most_common(1)[0][0]

11 changes: 11 additions & 0 deletions Coding Test/937.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution:
def reorderLogFiles(self, logs: List[str]) -> List[str]:
letters, digits = [], []
for log in logs:
if log.split()[1].isdigit():
digits.append(log)
else:
letters.append(log)

letters.sort(key=lambda x: (x.split()[1:], x.split()[0]))
return letters + digits
22 changes: 22 additions & 0 deletions Coding Test/Helpful.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Helpful Things

## Python Regex Module

[Python Regex](https://www.w3schools.com/python/python_regex.asp)

```python3
import re

re.findAll()
re.search()
re.split()
re.sub()
```

## Python Lambda

[Python Lambda](https://www.w3schools.com/python/python_lambda.asp)

## Python String

[Python String Method](https://www.w3schools.com/python/python_strings_methods.asp)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

파이썬 문자열 조작

> 125, 344
> 125, 344, 937, 819, 49, 5
## 자료구조

Expand Down

0 comments on commit 248c757

Please sign in to comment.