-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecodeString.py
More file actions
29 lines (25 loc) · 855 Bytes
/
DecodeString.py
File metadata and controls
29 lines (25 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution:
def decodeString(self, s: str) -> str:
result=[]
for c in s:
if(c==']'):
temp=""
p=result.pop()
while(p!='['):
temp+=p
p=result.pop()
n=""
p=result.pop()
while(len(result)>0 and '0'<=p and p<='9'):
n+=p
p=result.pop()
if(p>='0' and p<='9'):
n+=p
else:
result.append(p)
for _ in range(int(n[::-1])):
for i in range(len(temp)-1,-1,-1):
result.append(temp[i])
else:
result.append(c)
return ''.join(result)