Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ab1a6ba

Browse files
author
ccalderon
committed
feat: Leetcode 394: Decode String.
1 parent 9846735 commit ab1a6ba

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

394-decode-string.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def decodeString(self, s: str) -> str:
3+
stack = []
4+
5+
for char in s:
6+
if char is not "]":
7+
stack.append(char)
8+
else:
9+
sub_str = ""
10+
while stack[-1] is not "[":
11+
sub_str = stack.pop()+sub_str
12+
stack.pop()
13+
14+
multiplier = ""
15+
while stack and stack[-1].isdigit():
16+
multiplier = stack.pop() + multiplier
17+
18+
stack.append(int(multiplier)*sub_str)
19+
20+
return "".join(stack)

0 commit comments

Comments
 (0)