题目如下:

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

代码如下:

class Solution(object):def decodeString(self, s):""":type s: str:rtype: str"""stack = []for i in s:if i != ']':stack.append(i)continuerepeatStr = ''while len(stack) > 0:v = stack.pop(-1)if v == '[':breakrepeatStr = v + repeatStrtimes = ''while len(stack) > 0:v = stack.pop(-1)if v == ']':breakelif v == '[' or (v >= 'a' and v <= 'z'):stack.append(v)breaktimes = v + timesrepeatStr *= int(times)stack += list(repeatStr)return ''.join(stack)

转载于:https://www.cnblogs.com/seyjs/p/9417830.html

【leetcode】394. Decode String相关推荐

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

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

  2. 【leetcode】91. Decode Ways A-Z的字母表示1-26的数字,反向破解多少种字符串的可能性...

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

  3. 【LeetCode】87. Scramble String

    题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...

  4. 【leetcode】97. Interleaving String

    题目如下: 解题思路:本题可以采用动态规划的方法.记dp[i][j]表示用s1的前i个字符和s2的前j个字符能否组成s3的前(i+j)个字符,如果dp[i-1][j]是True的话,只要s1[i] = ...

  5. 【LeetCode】【HOT】394. 字符串解码(栈)

    [LeetCode][HOT]394. 字符串解码 文章目录 [LeetCode][HOT]394. 字符串解码 package hot;import java.util.LinkedList;pub ...

  6. 【LeetCode】字符串 string(共112题)

    [3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...

  7. 【Leetcode】79.单词搜索

    题目 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中"相邻"单元格是那些水平相邻或垂直相邻的单元格.同一个单元格 ...

  8. 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java

    [LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...

  9. 【LeetCode】【HOT】39. 组合总和(回溯)

    [LeetCode][HOT]39. 组合总和 文章目录 [LeetCode][HOT]39. 组合总和 package hot;import java.util.ArrayList; import ...

最新文章

  1. (Eclipse)(STM32) STM32在Eclipse編程
  2. setHeadAndPropagate
  3. How to download ABAP development Tool from Fiori Launchpad
  4. dict取值_Python基础数据类型「list、tuple、dict」
  5. (2017.9.27) 自定义列表项 list-style 使用心得
  6. Linux文件属性及如何修改文件属性
  7. python requests urlencode_关于requests的urlencode问题
  8. MySQL删除s表命令_SQL语句中删除表数据drop、truncate和delete的用法
  9. EAS后台事务的超时时长如何设置?
  10. CodeSmith简单示例
  11. LTE FDD 时频资源
  12. Python数据可视化(微课版)-简介
  13. 无理数存在性的几何证明
  14. Clover引导Windows10,Mac OS High Sierra,CentOS7 经验分享
  15. 张艺谋眼中的2020:科技的人间烟火味
  16. 微信服务器带宽是多少?使用大带宽服务器有什么好处?
  17. Unity 打包发布UWP 超详细
  18. 【运维心得】wps云文档被其他程序锁定了怎么办?
  19. 学霸用 Python 分析相亲网站数据,在两万异性中找到真爱!
  20. Android逆向之frida-dexdump脱壳分析某肿瘤sign

热门文章

  1. wireshark从入门到精通(协议排错安全篇)7
  2. shiro 授权介绍
  3. Android数据库专家秘籍(七)经验LitePal查询艺术
  4. Android使用Apache HttpClient发送GET、POST请求
  5. 介绍html CSS和JS的定义或引用
  6. centos7上安装配置tomcat8.5
  7. 在if里赋值要注意=和==的优先级,==优先于=
  8. C笔记(2014-12备份)
  9. 路由器配置与管理完全手册(Cisco篇)学习感想
  10. BCH压力测试取得圆满成功,最大区块达21.3MB