题目如下:

解题思路:这种题目和四则运算,去括号的题目很类似。解法也差不多。

代码如下:

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的更多相关文章

  1. 【LeetCode】394. Decode String 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 日期 题目地址:https://leetcode ...

  2. 【LeetCode】91. Decode Ways 解题报告(Python)

    [LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...

  3. 【LeetCode】481. Magical String 解题报告(Python)

    [LeetCode]481. Magical String 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http:/ ...

  4. 【LeetCode】880. Decoded String at Index 解题报告(Python)

    [LeetCode]880. Decoded String at Index 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  5. 【LeetCode】#344 Reverse String

    [Question] Write a function that takes a string as input and returns the string reversed. Example: G ...

  6. 【LeetCode】91. Decode Ways

    题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...

  7. 【LeetCode】091. Decode Ways

    题目: A message containing letters from A-Z is being encoded to numbers using the following mapping: ' ...

  8. 【LeetCode】344. Reverse String 解题报告(Java & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 新构建字符串 原地翻转 日期 题目地址:https://lee ...

  9. 【LeetCode】1023. Binary String With Substrings Representing 1 To N 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 日期 题目地址:https://leetcode.c ...

随机推荐

  1. sql时间类型相关

    1.现在时间 NOW() 示例: select * from users where date<now() 2.时间相减 INTERVAL ' DAY 示例: ' DAY 3.timestamp ...

  2. 类TreeSet

    /* * TreeSet能够对元素按照某种规则进行排序 * * 排序有2种方式 * A自然排序 * B比较器排序 * */ import java.util.TreeSet; /* * TreeSet ...

  3. jmeter模拟spike尖峰测

    jmeter模拟spike尖峰测试 概述 尖峰测试(Spike testing)在性能测试中属于压力测试的一个子集.指的是在某一瞬间或者多个频次下用户数和压力陡然增加的场景. 为了验证我们的网站在访问 ...

  4. K近邻实现

    1 定义画图函数,用来可视化数据分布 (注:jupyternotebook来编写的代码) import matplotlib.pyplot as plt import numpy as np %con ...

  5. 剑指offer--day04

    1.1题目:变态跳台阶:一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级.求该青蛙跳上一个n级的台阶总共有多少种跳法. 1.2解题思路: 当n=1时,结果为1: 当n=2时,结果为2: ...

  6. (136)leetcode刷题Python笔记——只出现一次的数字

    题目如下: 给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次.找出那个只出现了一次的元素. 说明: 你的算法应该具有线性时间复杂度. 你可以不使用额外空间来实现吗? 示例 1: ...

  7. [Web 前端] 011 css 背景属性

    1. 概览 参数 释义 background-color 背景颜色 background-image 背景图片 background-repeat 是否重复 background-position 定 ...

  8. sql下的xml配置文件中特殊使用的sql语句编写

    1.使用服用的sql语句------------查询学生表所有字段 <sql id="selectAllStuAll"> select stu.id,stu.name, ...

  9. MySQL-第十五篇使用连接池管理连接

    1.数据库连接池的解决方案是: 当应用程序启动时,系统主动建立足够的数据库连接,并将这些连接组成一个连接池.每次应用程序请求数据库连接时,无需重新打开连接,而是从连接池中取出已有的连接使用,使用完后不 ...

  10. 【洛谷p1309】瑞士轮

    因为太菜不会写P1310 表达式的值,就只能过来水两篇博客啦qwq 另外这个题我是开o2才过的(虽然是写了归并排序)(可能我太菜写的归并不是还可以“剪枝”吧qwq)哎,果真还是太菜啦qwq 所以准备写 ...