394. Decode String 解码icc字符串3[i2[c]]

[抄题]:

Given an encoded string, return it‘s decoded string.

The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer.

You may assume that the input string is always valid; No extra white spaces, square brackets are well-formed, etc.

Furthermore, you may assume that the original data does not contain any digits and that digits are only for those repeat numbers, k. For example, there won‘t be input like 3a or 2[4].

Examples:

s = "3[a]2[bc]", return "aaabcbc".
s = "3[a2[c]]", return "accaccacc".
s = "2[abc]3[cd]ef", return "abcabccdcdcdef".

[暴力解法]:

时间分析:

空间分析:

[优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

多层括号都没想到是stack,我去

[英文数据结构或算法,为什么不用别的数据结构或算法]:

两个stack可以分开处理字母和数组

[一句话思路]:

左括号就之前的不加了,右括号就开始append求和

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

[五分钟肉眼debug的结果]:

[总结]:

[复杂度]:Time complexity: O() Space complexity: O()

[算法思想:迭代/递归/分治/贪心]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

[代码风格] :

[是否头一次写此类driver funcion的代码] :

[潜台词] :

原文地址:https://www.cnblogs.com/immiao0319/p/9364499.html

时间: 2024-10-11 06:22:49

394. Decode String 解码icc字符串3[i2[c]]的相关文章

[LeetCode] Decode String 解码字符串

Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume th

Python 解LeetCode:394 Decode String

题目描述:按照规定,把字符串解码,具体示例见题目链接 思路:使用两个栈分别存储数字和字母 注意1: 数字是多位的话,要处理后入数字栈 注意2: 出栈时过程中产生的组合后的字符串要继续入字母栈 注意3: 记得字母出栈的时候字符要逆序组合成字符串 注意4: 不用字符串而用字母栈的原因是字符串的 join 效率会比字符串加法高一些 结果: 30 ms, beat 98.02% 缺点:判断是数字那里有点代码不简洁,可以把 j 挪到循环外面的 class Solution(object): def dec

394. Decode String

Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note thatk is guaranteed to be a positive integer. You may assume tha

Leetcode 394: Decode String

Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume th

[LC] 394. Decode String

Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a positive integer. You may assume tha

Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理)

Leetcode 91. Decode Ways 解码方法(动态规划,字符串处理) 题目描述 一条报文包含字母A-Z,使用下面的字母-数字映射进行解码 'A' -> 1 'B' -> 2 ... 'Z' -> 26 给一串包含数字的加密报文,求有多少种解码方式 举个例子,已知报文"12",它可以解码为AB(1 2),也可以是L (12) 所以解码方式有2种. 测试样例 Input: "0" "121212" "1010

Base64与String解码编码

String test = "test字符串"; //方法一 final Base64.Encoder encoder = Base64.getEncoder(); final Base64.Decoder decoder = Base64.getDecoder(); String encodeText = encoder.encodeToString(test.getBytes("UTF-8")); System.out.println(encodeText);

【LeetCode】- String to Integer (字符串转成整形)

[ 问题: ] Hint:Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes:It is intended for this problem to be specified vaguely (ie, no given input specs). Y

java 创建string对象机制 字符串缓冲池 字符串拼接机制

1.String str = new String("hello"); 创建了2个对象,1.检查常量池中有没有hello,没有的话,创建对象放到常量池中,再创建对象放到堆中.如果常量池有hello对象,则只创建一个对象并放到堆中. 2.字符串常量池在方法区 3.String str = "hello";检查常量池有无hello,如果有,则把指向该对象,如果没有,创建对象放在常量池里. 4.intern()方法.把字符串变成常量池里的字符串:如果常量池中已经包含了等于