题目可能和大家的有些不一样,题目没存,做了的应该知道题目。。 第1题,压缩算法 大意是将[3|AB]这样的字符串转为ABABAB。这个题典型的做法是递归,因为可能有嵌套的情形。这个题有点像LeetCode 394。 但是,为了追求速度,使用正则表达式直接循环替换,迅速解决。 import re s = input() while '[' in s: for b in re.findall(r'\[\d+\|[A-Z]+\]', s): n, c = re.findall(r'\[(\d+)\|([A-Z]+)\]', b)[0] ...