leetcode——394. 字符串解码

江枫思渺然 提交于 2019-12-03 11:21:45

这道题也不是我自己做出来的,只能说大佬牛逼!!!

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!