Skip to content
This repository was archived by the owner on Apr 20, 2024. It is now read-only.

Commit c6e97d6

Browse files
committed
create solution.py for problem26
1 parent c1d121e commit c6e97d6

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

problem26/Solution.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def decodeString(s):
2+
stack = []
3+
for ch in s:
4+
if ch != ']':
5+
stack.append(ch)
6+
continue
7+
substr = ""
8+
while True:
9+
item = stack.pop()
10+
if item == '[': continue
11+
if item.isalpha():
12+
substr = item + substr
13+
continue
14+
num = item
15+
while stack and stack[-1].isdigit():
16+
num = stack.pop() + num
17+
stack.append(int(num) * substr)
18+
break
19+
return "".join(stack)
20+
21+
def main():
22+
sList = ["3[a]2[bc]", "3[a2[c]]", "2[abc]3[cd]ef"]
23+
for s in sList:
24+
print("Decoded = ", decodeString(s))
25+
26+
if __name__ == "__main__":
27+
main()
28+
29+

0 commit comments

Comments
 (0)