【leetcode】394. Decode String
题目如下:

解题思路:这种题目和四则运算,去括号的题目很类似。解法也差不多。
代码如下:
class Solution(object):
def decodeString(self, s):
"""
:type s: str
:rtype: str
"""
stack = []
for i in s:
if i != ']':
stack.append(i)
continue
repeatStr = ''
while len(stack) > 0:
v = stack.pop(-1)
if v == '[':
break
repeatStr = v + repeatStr
times = ''
while len(stack) > 0:
v = stack.pop(-1)
if v == ']':
break
elif v == '[' or (v >= 'a' and v <= 'z'):
stack.append(v)
break
times = v + times
repeatStr *= int(times)
stack += list(repeatStr)
return ''.join(stack)
【leetcode】394. Decode String的更多相关文章
- 【LeetCode】394. Decode String 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 日期 题目地址:https://leetcode ...
- 【LeetCode】91. Decode Ways 解题报告(Python)
[LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
- 【LeetCode】481. Magical String 解题报告(Python)
[LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...
- 【LeetCode】880. Decoded String at Index 解题报告(Python)
[LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...
- 【LeetCode】#344 Reverse String
[Question] Write a function that takes a string as input and returns the string reversed. Example: G ...
- 【LeetCode】91. Decode Ways
题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...
- 【LeetCode】091. Decode Ways
题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...
- 【LeetCode】344. Reverse String 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 新构建字符串 原地翻转 日期 题目地址:https://lee ...
- 【LeetCode】1023. Binary String With Substrings Representing 1 To N 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...
随机推荐
- Linux添加目录到环境变量以及添加Sublime Text到环境变量
本文主要介绍了Linux添加目录到环境变量以及添加Sublime Text到环境变量,通过具体的解释说明,让我们从中学到Linux添加目录到环境变量以及添加Sublime Text到环境变量的精髓所在 ...
- mysql 5.6多库并行复制原理
首先,要开启这个并行复制,需要设定slave_parallel_workers参数,这个参数如果设定成0的话代表不使用并行,relaylog由sql线程执行,表现和之前版本一致.当这个参数设置成n时, ...
- (转)datagridview 自定义列三步走
本文转载自:http://blog.csdn.net/zx13525079024/article/details/4814642 我们如果想自定义实现datagridview的某列,例如是datagr ...
- leetcode 36有效的数独
建立一个哈希表,每次查找,如果对应的列col,行row,小方格box中的数出现第二次,那么数独不合法: 据说还有深度优先搜索的方法,表示没有听懂:) class Solution { public: ...
- 记一次odoo创建新的模块时,但是在odoo web界面找不到应用的案例
原因就是在odoo.conf配置文件中没有说明 模块查找的路径
- nginx下使用asan和valgrind两个静态检查工具
1.valgrind valgrind安装:参考:https://blog.csdn.net/justheretobe/article/details/52986461 wegit:http://va ...
- curl发json
linux 模拟post请求 curl -X POST \ -H "Content-Type: application/json" \ -H "token:GXJP1cl ...
- spring mvc 接受数组
@RequestParam(value = "customerIds[]")Integer[] customerIds 加上 requestParam value设置为 &qu ...
- struts2 token 防止表单重复提交
1.jsp页面 输入框,提交按钮 <%@ page language="java" contentType="text/html" pageEncodi ...
- Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分
其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...