Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def decodeString(self, s_: str) -> str:
- s = []
- for c in s_:
- if c == "[":
- s.append(Solution)
- elif c == "]":
- ts = s.pop()
- s.pop()
- tn = s.pop()
- s.append(ts * tn)
- elif "0" <= c <= "9":
- if s and isinstance(s[-1], int):
- s[-1] *= 10
- s[-1] += int(c)
- else:
- s.append(int(c))
- else:
- s.append(c)
- while (
- len(s) > 1 and
- isinstance(s[-1], str) and
- isinstance(s[-2], str)
- ):
- t = s[-2] + s[-1]
- s.pop()
- s.pop()
- s.append(t)
- return s[0]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement