题目如下:

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

代码如下:

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. python一个月能学成嘛-0基础学Python,1个月写爬虫,走了哪些弯路?
  2. 百练OJ:2972: 确定进制
  3. ORA-04031错误导致宕机案例分析
  4. leading dimension
  5. fopen在linux中打开文件夹,plain C:用fopen()打开一个目录
  6. python格式化读取文件_python文本读写与格式化
  7. linux服务器系统_利用Zabbix监控系统监测Linux服务器系统时间是否准确完美实现...
  8. 网页常用分享代码大全——整理摘抄至他人嘿嘿
  9. mysql查询id为偶数_MySQL中查询中位数?
  10. 监控易:智慧高校一体化综合运维解决方案
  11. 【MMD动作下载】随心所欲mercy(Kimagure Mercy)
  12. 河南省第三届金盾信安杯网络安全大赛部分wp
  13. 编写WPF应用程序实现以下功能:定义一个RandomHelp类,该类提供一个静态的GetIntRandomNumber方法,一个静态的GetDoubleRandomNumber方法。
  14. 回归分析beta值的标准_标准回归系数引用
  15. 服务器开机显示检查电缆,电脑开机显示无VGA电缆是怎么回事,求答!
  16. 51nod 1423:最大二“货”
  17. 大学这么多比赛,我该参加哪个?
  18. 中国人为什么这么爱面子?
  19. 图像处理----形态学滤波
  20. 计算机文化基础知识在未来工作中的应用论文,计算机文化基础论文

热门文章

  1. velocity 模板引擎
  2. information_schema.triggers 学习
  3. 45个超实用的JavaScript技巧及最佳实践(一)
  4. UTF-8 BOM(EF BB BF)
  5. HttpClient乱码问题
  6. xCode中工程相关的一些处理:一个工程包含多个Target的用途和使用方法【转】...
  7. xm console无法联接guest问题的解决
  8. Linux的企业-Redis数据库、缓存和哨兵Sentinal、Redis高可用
  9. 《软件定义网络:基于OpenFlow的SDN》一一2.5 本章总结
  10. Gitlab完整搭建手册+排错