2018-12-19 leetcode Decode String Decode Stringstack version - 32ms 123456789101112131415161718192021class Solution: def decodeString(self, s): """ :type s: str :rtype: str """ stack = [] stack.append(["", 1]) num = "" for ch in s: if ch.isdigit(): num += ch elif ch == '[': stack.append(["", int(num)]) num = "" elif ch == ']': st, k = stack.pop() stack[-1][0] += st*k else: stack[-1][0] += ch return stack[0][0] test code 12In [109]: s = Solution(); t = s.decodeString("3[a]2[bc]"); print(t)aaabcbc leet code Newer Path Sum III Older Best Time to Buy and Sell Stock with Cooldown