Ai
1 Star 2 Fork 5

LilithSangreal/LeetCode-Solutions

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
decode-string.py 660 Bytes
一键复制 编辑 原始数据 按行查看 历史
Sanghee Kim 提交于 2019-01-26 19:52 +08:00 . update decode-string.py
# Time: O(n)
# Space: O(n)
class Solution(object):
def decodeString(self, s):
"""
:type s: str
:rtype: str
"""
curr, nums, strs = [], [], []
n = 0
for c in s:
if c.isdigit():
n = n * 10 + ord(c) - ord('0')
elif c == '[':
nums.append(n)
n = 0
strs.append(curr)
curr = []
elif c == ']':
strs[-1].extend(curr * nums.pop())
curr = strs.pop()
else:
curr.append(c)
return "".join(strs[-1]) if strs else "".join(curr)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/LilithSangreal/LeetCode-Solutions.git
git@gitee.com:LilithSangreal/LeetCode-Solutions.git
LilithSangreal
LeetCode-Solutions
LeetCode-Solutions
master

搜索帮助