class Solution {
public:
string decodeString(string s) {
stack<string> chars;
stack<int> nums;
string res;
int num = ; for (char c: s) {
if (isdigit(c))
num = num * + (c - '');
else if (isalpha(c)) {
res += c;
} else if (c == '[') {
chars.push(res);
nums.push(num);
res = "";
num = ;
} else {
string tmp = res;
for (int i = ; i < nums.top() - ; i++)
res += tmp;
res = chars.top() + res;
chars.pop();
nums.pop();
}
} return res;
}
};

leetcode394的更多相关文章

  1. [Swift]LeetCode394. 字符串解码 | Decode String

    Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...

  2. LeetCode-394. Decode String(DFS)

    Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...

  3. LeetCode394 字符串解码

    给定一个经过编码的字符串,返回它解码后的字符串. 编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次.注意 k 保证为正整数. 你可 ...

随机推荐

  1. JavaScript之循环

    我是昨天的小尾巴...https://blog.csdn.net/weixin_42217154/article/details/81182817 3.2 循环结构 循环结构是指在程序中需要反复执行某 ...

  2. 关于windows下的makefile学习

    文中部分引用自:http://bbs.chinaunix.net/forum.php?mod=viewthread&tid=408225 windows下makefile环境配置见于:http ...

  3. python学习之路06——字符串

    字符串 1.概念 字符串就是由若干个字符组成的有限序列 字符:字母,数字,特殊符号,中文 表示形式:采用的单引号或者双引号 注意:字符串属于不可变实体 2.创建字符串 str1 = "hel ...

  4. Codeforces 1080C- Masha and two friends

    AC代码 #include <bits/stdc++.h> #define ll long long const int maxn=1e6+10; using namespace std; ...

  5. js封装选项卡

    <div class="forestcamp_box"> <img src="img/home_02.jpg" /> <div c ...

  6. ViewpagerHandler

    import android.os.AsyncTask; import android.os.Handler; import android.os.Message; import android.su ...

  7. idc市场

    机房 idc服务商 ============================== 电信1.古城热线-西部数据中心于2001年正式投入运营,有经济技术开发区和高新技术产业开发区两个核心机房高新路电信广场 ...

  8. LOJ 3057 「HNOI2019」校园旅行——BFS+图等价转化

    题目:https://loj.ac/problem/3057 想令 b[ i ][ j ] 表示两点是否可行,从可行的点对扩展.但不知道顺序,所以写了卡时间做数次 m2 迭代的算法,就是每次遍历所有不 ...

  9. repository test has failed 错误

    这里给自己一个警告,当我在idea中准备clone gitlab上的项目时,这个链接竟然一直在报:repository test has failed 错误 这个是gitlab上复制下来的原链接:ht ...

  10. Python判断语句

    什么是判断语句 如果 今天是周六或者周日: 约妹子 如果 今天是情人节: 买玫瑰 如果 今天发工资: 先还信用卡的钱 如果 有剩余: 又可以happy了,O(∩_∩)O哈哈~ 否则: 啊啊啊啊,等30 ...