---
tags: data_structure_python
---
# Encode and Decode Strings
https://www.lintcode.com/problem/659/
```python=
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
res = ""
n = len(strs)
for i in range(n-1):
res += strs[i] + ":;"
res += strs[n-1]
return res
"""
@param: str: A string
@return: dcodes a single string to a list of strings
"""
def decode(self, str):
# write your code here
print(str)
res = []
slow, fast = 0, 0
while fast < len(str):
if str[fast-1] == ":" and str[fast] == ";":
res.append(str[slow:fast-1])
slow = fast + 1
fast += 1
res.append(str[slow:])
return res
```