【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 ...
随机推荐
- php对bom的处理
通常只有在windows的notepad中 , 创建文本文件, 保存为UTF-8 时, 它会自动添加3个字节: ef bb bf. 用editplus来看txt文件就可以看得很清楚. 但是, 只有wi ...
- 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_05 IO字符流_3_字符输出流_Writer类&FileWriter类
- c# Thread5——线程同步之基本原子操作。Mutex互斥量的使用
之前的博文也说到了如果多线程对于访问的公共资源操作都是原子操作,那么可以避免竞争条件.关于多线程的竞争可以百度. 1.执行最基本的原子操作 c#提供了一系列供我们使用的原子操作的方法和类型,比如我们的 ...
- mysql数据库连接 application.properties
# 数据库链接信息mysql.driver=com.mysql.cj.jdbc.Drivermysql.url=jdbc:mysql://localhost:3306/xxxx?characterEn ...
- SqlServer 主重复制
一.准备工作: 主数据库服务器: OS:Windows Server 2008 R2 DB: SQL Server 2008 R2 Hostname : CXMasterDB IP: 192.1 ...
- Java io基础
1.什么是IO? Java IO即Java 输入输出系统.不管我们编写何种应用,都难免和各种输入输出相关的媒介打交道,其实和媒介进行IO的过程是十分复杂的,这要考虑的因素特别多,比如我们要考虑和哪种媒 ...
- [Python3] 013 集合:你不能两次进入同一个集合
目录 0. 集合的独白 1. 集合的创建 2. 集合的特性 (1) 概述 (2) 少废话,上例子 3. 集合的遍历 4. 集合内涵 5. 集合的内置方法 6. 可供集合使用的一些方法/函数 (1) 又 ...
- java基础笔记(1)
---恢复内容开始--- JVM:java虚拟机,java跨平台是通过JVM来实现的, 将java文件执行的过程:源文件----编译器----->字节码文件------解释器------> ...
- [2019杭电多校第五场][hdu6628]permutation 1
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6628 题意为求字典序第k小的差异数组,差异数组p满足p[i]=a[i+1]-a[i]. 头铁的爆搜,因 ...
- [CCPC-Wannafly & Comet OJ 夏季欢乐赛(2019)]飞行棋
题目链接:https://www.cometoj.com/contest/59/problem/E?problem_id=2714 求期望并且一堆转移基本上就是期望dp了(叉腰 照常的设dp[i]表示 ...