forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevyejin.py
More file actions
33 lines (30 loc) ยท 830 Bytes
/
devyejin.py
File metadata and controls
33 lines (30 loc) ยท 830 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class Solution:
"""
@param: strs: a list of strings
@return: encodes a list of strings to a single string.
"""
def encode(self, strs):
# write your code here
result = ""
for s in strs:
result += str(len(s)) + "@" + s
return result
"""
@param: str: A string
@return: decodes a single string to a list of strings
"""
def decode(self, str):
# write your code here
result = []
i = 0
while i < len(str):
j = i
# ์์์ ์๋ ๊ฒฝ์ฐ
while str[j] != "@":
j += 1
# ์์์ ์ธ ๊ฒฝ์ฐ
length = int(str[i:j])
word = str[j + 1: j + 1 + length]
result.append(word)
i = j + 1 + length
return result