Decode String LeetCode solution in Python

1
class Solution:
2
def decodeString(self, s: str) -> str:
3
stk = []
4

5
for i in range(len(s)):
6

7
if s[i] != "]":
8
stk.append(s[i])
9
else:
10
strr = ""
11
while stk[-1] != "[":
12
strr = stk.pop() + strr
13
stk.pop()
14

15
num = ""
16
while stk and stk[-1].isdigit():
17
num = stk.pop() + num
18

19
stk.append(int(num) * strr)
20

21
return "".join(stk)

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0