Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2f30687

Browse files
committed
add 394 stack
1 parent 4bc6b51 commit 2f30687

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

‎LeetCodeSolutions/150.py‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#==================================================
2-
#==> Title:
2+
#==> Title: 150. 逆波兰表达式求值
33
#==> Author: Zhang zhen
44
#==> Email: hustmatnoble.gmail.com
55
#==> GitHub: https://github.com/MatNoble
6-
#==> Date:
6+
#==> Date: 2/2/2021
77
#==================================================
88

9+
"""
10+
https://leetcode-cn.com/problems/evaluate-reverse-polish-notation/
11+
"""
12+
913
from typing import List
1014
class Solution:
1115
def evalRPN(self, tokens: List[str]) -> int:

‎LeetCodeSolutions/394.py‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#==================================================
2+
#==> Title: 394. 字符串解码
3+
#==> Author: Zhang zhen
4+
#==> Email: hustmatnoble.gmail.com
5+
#==> GitHub: https://github.com/MatNoble
6+
#==> Date: 2/2/2021
7+
#==================================================
8+
9+
"""
10+
https://leetcode-cn.com/problems/decode-string/
11+
"""
12+
13+
class Solution:
14+
def decodeString(self, s: str) -> str:
15+
stack, res, multi = [], "", 0
16+
for c in s:
17+
if c == '[':
18+
stack.append([multi, res])
19+
res, multi = "", 0
20+
elif c == ']':
21+
cur_multi, last_res = stack.pop()
22+
res = last_res + cur_multi * res
23+
elif '0' <= c <= '9':
24+
multi = multi * 10 + int(c)
25+
else:
26+
res += c
27+
return res
28+
29+
# 参考:https://leetcode-cn.com/problems/decode-string/solution/decode-string-fu-zhu-zhan-fa-di-gui-fa-by-jyd/
30+
31+
mat = Solution()
32+
s = "3[a]2[bc]"
33+
s = "abc3[cd]xyz"
34+
# s = "2[abc]3[cd]ef"
35+
# s = "3[a2[c]]"
36+
s = "2[2[2[ab]]]"
37+
mat.decodeString(s)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /