Skip to content

Commit 6c77710

Browse files
committed
Time: 0 ms (100%), Space: 17.9 MB (34.98%) - LeetHub
1 parent 4fc02d4 commit 6c77710

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

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+
current_str = ''
5+
current_num = 0
6+
7+
for char in s:
8+
if char.isdigit():
9+
current_num = current_num * 10 + int(char)
10+
elif char == '[':
11+
stack.append((current_str, current_num))
12+
current_str = ''
13+
current_num = 0
14+
elif char == ']':
15+
last_str, num = stack.pop()
16+
current_str = last_str + current_str * num
17+
else:
18+
current_str += char
19+
20+
return current_str

0 commit comments

Comments
 (0)