【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 ...
随机推荐
- isinstance(object, classinfo) class type(name, bases, dict)
w https://docs.python.org/3/library/functions.html#isinstance
- thinkphp5.0学习笔记(一)基础知识与URL访问
1.目录结构: 其中thinkphp子目录是框架核心目录 thinkphp结构: 2.入口文件 默认自带的入口文件位于public/index.php 应用目录为application,其结构: in ...
- Delphi XE2 之 FireMonkey 入门(3) - 关于 TPosition
把 FireMonkey 简称为 FM 吧. FM 的窗体继续使用 Left.Top 属性, 但更多控件不是了. //FM 控件的位置控制不再是 Left.Top, 取而代之的是 Position 属 ...
- Application.Restore不起作用了
http://www.myexception.cn/delphi/695243.html Application.Restore不起作用了窗体上只有一个Button和一个Timer(1秒计时)代码如下 ...
- 券商VIP交易通道
打新不成就炒新.随着新股发行上市的再次重启,巨大的获利机会引来投资者的争相竞逐,可并非所有投资者都能抢到新股筹码.“每天都在涨停板追这些新股,但从来没有买到过.”证券时报记者在采访中听到不少中小散户如 ...
- kali安装教程
首先在vm里面新建虚拟机,直接选择典型,然后下一步. 1 2 然后到了这一步,选择中间的安装程序光盘镜像文件,然后去文件里面找你自己下载的镜像,这时候可能系统会出现无法检测此光盘镜像中的操作系 ...
- UVa 12169 Disgruntled Judge 紫书
思路还是按照紫书,枚举a,得出b, 然后验证. 代码参考了LRJ的. #include <cstdio> #include <iostream> using namespace ...
- 前端005/React生命周期
ES6中React生命周期 一.React生命周期 React生命周期主要包括三个阶段:初始化阶段.运行中阶段和销毁阶段. 在React不同的生命周期里,会依次触发不同的钩子函数. 二.React的生 ...
- python基础-5 冒泡排序、递归
上节总结 一.上节内容补充回顾 1.lambda func = lambda x,y: 9+x 参数: x,y 函数体:9+x ==> return 9+x func: 函数名 def func ...
- 利用Redisson实现分布式锁及其底层原理解析
Redis介绍 参考地址:https://blog.csdn.net/turbo_zone/article/details/83422215 redis是一个key-value存储系统.和Memcac ...