-
-
Notifications
You must be signed in to change notification settings - Fork 336
Expand file tree
/
Copy pathsangbeenmoon.py
More file actions
43 lines (33 loc) · 940 Bytes
/
sangbeenmoon.py
File metadata and controls
43 lines (33 loc) · 940 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
34
35
36
37
38
39
40
41
42
43
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 = ""
delimiter = ":;"
for i, str in enumerate(strs):
result = result + str
if i != len(strs):
result = result + delimiter
print(result)
return result
"""
@param: str: A string
@return: decodes a single string to a list of strings
"""
def decode(self, str):
result = []
i = 0
delimiter = ":;"
while i < len(str):
j = i
while j < len(str) - 1:
if str[j:j+2] == delimiter:
result.append(str[i:j])
break
else:
j = j + 1
i = j + 2
return result