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. 使用map()的小陷阱:parseInt

    假设我们想要把一个字符串数组的每一项转换成整数,我们很自然就想到了把parseInt作为回调函数传给map()函数,但这样做可能会出现意想不到的结果: var strArr = ["1&qu ...

  2. phpcms 路由配置

    这是一个由apache多站点配置引发的"血案",本以为是本地多站点配置的问题,结果找了半天没找到相关配置,最后还是问的大腿,同时也了解一些关于c盘hosts文件的映射作用以及使用 ...

  3. 网络编程 生产者消费者模型 GiL

    守护进程: 注意事项: 1.必须在p.start()前 2.守护进程不能开子进程 3.如果主进程的运行时间快于子进程,那么就只有主进程的结果,没有守护进程的结果,因为守护进程没有进行完.反之会得到两个 ...

  4. 姿势估计实验-Realtime_Multi-Person_Pose_Estimation-CMU

    前言: 论文及源代码网址: https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation 地址2: https://github.com/ ...

  5. 拓扑排序bfs_dfs

    dfs #include <cstdio> #include <cstring> using namespace std; ; struct Edge{ int lst; in ...

  6. hibernate模拟(转载)

    package simulation; /** * * @author Administrator * */ public class User { private int id; private S ...

  7. mingw using pthread

    转载http://www.cnblogs.com/tfanalysis/p/5505163.html ftp://sourceware.org/pub/pthreads-win32/ 有的时候需要使用 ...

  8. session token两种登陆方式

    Session 和 Token 其实Session和Token总体上还是很相似的,但是也有以下区别: 1. 过期时间:Session的过期时间存在cookie的Max-age字段,Token的过期时间 ...

  9. PythonStudy——格式化输入小练习

    # 练习:用户输入姓名.年龄.工作.爱好 ,然后打印成以下格式# ------------ info of Egon -----------# Name : Egon# Age : 22# Sex : ...

  10. nomad 0.9 新特性

    内容摘自github Affinities and Spread: Jobs may now specify affinities towards certain node attributes. A ...