We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4fc02d4 commit 6c77710Copy full SHA for 6c77710
1 file changed
0394-decode-string/0394-decode-string.py
@@ -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
13
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