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

Skip to content

Commit c8bcb91

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

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

394-decode-string.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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] != "[":
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)
21+

0 commit comments

Comments
 (0)