【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)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相关推荐
- 【LeetCode】91. Decode Ways 解题报告(Python)
[LeetCode]91. Decode Ways 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fux ...
- 【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: ...
- 【LeetCode】87. Scramble String
题目: Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty subs ...
- 【leetcode】97. Interleaving String
题目如下: 解题思路:本题可以采用动态规划的方法.记dp[i][j]表示用s1的前i个字符和s2的前j个字符能否组成s3的前(i+j)个字符,如果dp[i-1][j]是True的话,只要s1[i] = ...
- 【LeetCode】【HOT】394. 字符串解码(栈)
[LeetCode][HOT]394. 字符串解码 文章目录 [LeetCode][HOT]394. 字符串解码 package hot;import java.util.LinkedList;pub ...
- 【LeetCode】字符串 string(共112题)
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...
- 【Leetcode】79.单词搜索
题目 给定一个二维网格和一个单词,找出该单词是否存在于网格中. 单词必须按照字母顺序,通过相邻的单元格内的字母构成,其中"相邻"单元格是那些水平相邻或垂直相邻的单元格.同一个单元格 ...
- 【LeetCode】Minimum Depth of Binary Tree 二叉树的最小深度 java
[LeetCode]Minimum Depth of Binary Tree Given a binary tree, find its minimum depth. The minimum dept ...
- 【LeetCode】【HOT】39. 组合总和(回溯)
[LeetCode][HOT]39. 组合总和 文章目录 [LeetCode][HOT]39. 组合总和 package hot;import java.util.ArrayList; import ...
最新文章
- (Eclipse)(STM32) STM32在Eclipse編程
- setHeadAndPropagate
- How to download ABAP development Tool from Fiori Launchpad
- dict取值_Python基础数据类型「list、tuple、dict」
- (2017.9.27) 自定义列表项 list-style 使用心得
- Linux文件属性及如何修改文件属性
- python requests urlencode_关于requests的urlencode问题
- MySQL删除s表命令_SQL语句中删除表数据drop、truncate和delete的用法
- EAS后台事务的超时时长如何设置?
- CodeSmith简单示例
- LTE FDD 时频资源
- Python数据可视化(微课版)-简介
- 无理数存在性的几何证明
- Clover引导Windows10,Mac OS High Sierra,CentOS7 经验分享
- 张艺谋眼中的2020:科技的人间烟火味
- 微信服务器带宽是多少?使用大带宽服务器有什么好处?
- Unity 打包发布UWP 超详细
- 【运维心得】wps云文档被其他程序锁定了怎么办?
- 学霸用 Python 分析相亲网站数据,在两万异性中找到真爱!
- Android逆向之frida-dexdump脱壳分析某肿瘤sign
热门文章
- wireshark从入门到精通(协议排错安全篇)7
- shiro 授权介绍
- Android数据库专家秘籍(七)经验LitePal查询艺术
- Android使用Apache HttpClient发送GET、POST请求
- 介绍html CSS和JS的定义或引用
- centos7上安装配置tomcat8.5
- 在if里赋值要注意=和==的优先级,==优先于=
- C笔记(2014-12备份)
- 路由器配置与管理完全手册(Cisco篇)学习感想
- BCH压力测试取得圆满成功,最大区块达21.3MB