Advertisement
kosievdmerwe

Untitled

Dec 18th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. class Solution:
  2.     def decodeString(self, s_: str) -> str:
  3.         s = []
  4.         for c in s_:
  5.             if c == "[":
  6.                 s.append(Solution)
  7.             elif c == "]":
  8.                 ts = s.pop()
  9.                 s.pop()
  10.                 tn = s.pop()
  11.                 s.append(ts * tn)
  12.             elif "0" <= c <= "9":
  13.                 if s and isinstance(s[-1], int):
  14.                     s[-1] *= 10
  15.                     s[-1] += int(c)
  16.                 else:
  17.                     s.append(int(c))
  18.             else:
  19.                 s.append(c)
  20.                
  21.                
  22.             while (
  23.                 len(s) > 1 and
  24.                 isinstance(s[-1], str) and
  25.                 isinstance(s[-2], str)
  26.             ):
  27.                 t = s[-2] + s[-1]
  28.                 s.pop()
  29.                 s.pop()
  30.                 s.append(t)
  31.        
  32.         return s[0]
  33.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement