|
|
发表于 2020-4-20 11:45:48
|
显示全部楼层
# 找到所有的方括号,依次进行解码
- def decode(encoding_str):
- def repeat(string, num):
- str1 = ""
- for i in range(num):
- str1 += string
- return str1
- left_index = encoding_str.find('[')
- while left_index != -1:
- right_index = encoding_str.find(']')
- reused_str = repeat(encoding_str[left_index+1:right_index], int(encoding_str[left_index-1]))
- encoding_str = encoding_str.replace(encoding_str[left_index-1:right_index+1], reused_str)
- left_index = encoding_str.find('[')
- return encoding_str
复制代码 |
|