【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 ...
随机推荐
- Apache2.4+PHP7.2环境搭建
Editplus生成码:http://www.jb51.net/tools/editplus/ 阿帕奇下载地址:https://www.apachehaus.com/cgi-bin/download. ...
- p4841 城市规划
分析 https://www.luogu.org/blog/DRA/solution-p4841 代码(似乎附赠了一个全家桶呢) #pragma GCC optimize(2) #pragma GCC ...
- 小刀jsonp跨域
经常说到jsonp,今天理一理. 同源策略 同协议,同域名,同端口: 会限制你的ajax,iframe操作,窗口信息的传递,无法获取跨域的cookie.localStorage.indexDB等: j ...
- 读Dubbo源码,学习SPI
核心类 ExtensionLoader 使用方法 定义接口,使用@SPI标记 @SPI("impl1") public interface SimpleExt { // @Adap ...
- Numpy和Pandas
NumPy是高性能科学计算和数据分析的基础包.数据结构为ndarray,一般有三种方式来创建.ndarray是N-Dimensions-Array(N维数组)的简称,ndarray要求元素数据类型一致 ...
- Week 5 - 529.Minesweeper
529.Minesweeper Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char ma ...
- delphi 静态3维数组。 严重占用堆栈 切记。 应该用动态数组, 非要用静态数组的话, 要在编译器里 把 堆栈 调大
delphi 代码正确, 但是运行就崩溃. 原因为 定义了 一些 静态3维数组. 应该扩大 软件的 堆栈 设置. 然后正常解决问题 静态3维数组. 严重占用堆栈 切记. 应该用动态 ...
- Java 与 C++ 的比较
参考 Java 中,一切皆是类 Java 中,所有数据或方法都要放在类中.如果想获得与全局函数等价的功能,可将static方法和static数据放在类里.而 C++ 中有 struct 结构.enum ...
- python自动化测试接口测试http请求报404的其中一个坑
在敲代码的路上 ,总是会遇到报错找半天原因,最后发现是个低级错误的时候! 这不今天为了这个错误找了半天原因.......... http请求接口测试中报404我遇到的大部分都是url的问题: 但是今天 ...
- git比较重要但是又容易忘记的操作
git rebase head~1 把多次commit合并成一次 git reset head 撤销已缓存的内容 git checkout . git stash 去除改动未提交的代码