Skip to content

Commit 9b859d0

Browse files
committed
update 2 problems
1 parent 758a354 commit 9b859d0

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
class Solution:
2+
"""
3+
@param: strs: a list of strings
4+
@return: encodes a list of strings to a single string.
5+
"""
6+
def encode(self, strs):
7+
# write your code here
8+
result = ""
9+
for word in strs:
10+
word_size = len(word)
11+
result += str(word_size) + "#" + word
12+
13+
return result
14+
# input ["lint","code","love","you"]
15+
# output "4#lint4#code4#love3#you"
16+
17+
"""
18+
@param: str: A string
19+
@return: decodes a single string to a list of strings
20+
"""
21+
def decode(self, str):
22+
# write your code here
23+
result = []
24+
i = 0
25+
while i < len(str):
26+
j = i
27+
while str[j] != "#": #find the position of '#'
28+
j += 1
29+
30+
my_number = int(str[i:j])
31+
32+
start = j + 1 # add 1 to skip '#'
33+
end = j + 1 + my_number
34+
35+
result.append(str[start:end])
36+
i = end
37+
38+
return result
39+
# input "4#lint4#code4#love3#you"
40+
# output ["lint","code","love","you"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Solution:
2+
def groupAnagrams(self, strs: List[str]) -> List[List[str]]:
3+
group_anagram = defaultdict(list)
4+
# ์ดˆ๊ธฐํ™”: ํ‚ค๊ฐ€ ์—†์œผ๋ฉด ์ž๋™์œผ๋กœ list() ์ฆ‰, []๋ฅผ ์‹คํ–‰ํ•ด์„œ ๊ฐ’์„ ๋งŒ๋“ฆ
5+
6+
for word in strs:
7+
sorted_word = ''.join(sorted(word))
8+
group_anagram[sorted_word].append(word)
9+
10+
return list(group_anagram.values())

โ€Žword-break/daiyongg-kim.pyโ€Ž

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
3+
4+
""" Failed Attempt
5+
class Solution:
6+
def wordBreak(self, s: str, wordDict: List[str]) -> bool:
7+
8+
for word in wordDict:
9+
if word in s:
10+
s = s.replace(word, '')
11+
else:
12+
return False
13+
return len(s) == 0
14+
"""

0 commit comments

Comments
ย (0)