这道题也不是我自己做出来的,只能说大佬牛逼!!!
class Solution(object): def decodeString(self, s): """ :type s: str :rtype: str """ stack, res, multi = [], "", 0 for c in s: if c == '[': stack.append([multi, res]) res, multi = "", 0 elif c == ']': cur_multi, last_res = stack.pop() res = last_res + cur_multi * res elif '0' <= c <= '9': multi = multi * 10 + int(c) else: res += c return res
执行用时 :24 ms, 在所有 python 提交中击败了45.24%的用户
内存消耗 :11.7 MB, 在所有 python 提交中击败了20.90%的用户
——2019.11.4