leetcode394
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的更多相关文章
- [Swift]LeetCode394. 字符串解码 | Decode String
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...
- LeetCode-394. Decode String(DFS)
Given an encoded string, return it's decoded string. The encoding rule is: k[encoded_string], where ...
- LeetCode394 字符串解码
给定一个经过编码的字符串,返回它解码后的字符串. 编码规则为: k[encoded_string],表示其中方括号内部的 encoded_string 正好重复 k 次.注意 k 保证为正整数. 你可 ...
随机推荐
- Oracle创建视图的一个问题
问题: 在用户user1中创建视图,查询内容包含user2下的表数据, 创建视图的时候提示“权限不足”.执行如下语句: --为USER1授权 GRANT CREATE ANY TABLE TO USE ...
- VS使用Nuget教程详解 Visual studio 安装第三方的组件库
首先说明Nuget是什么呢?它的官方是:https://www.nuget.org/ 官方主页的介绍如下: What is NuGet? NuGet is the package manager fo ...
- 如何用Caffe训练自己的网络-探索与试验
现在一直都是用Caffe在跑别人写好的网络,如何运行自定义的网络和图片,是接下来要学习的一点. 1. 使用Caffe中自带的网络模型来运行自己的数据集 参考 [1] :http://www.cnblo ...
- JAVA高级篇(一、JVM基本概念)
一.什么是JVM VM的中文名称叫Java虚拟机,它是由软件技术模拟出计算机运行的一个虚拟的计算机. JVM也充当着一个翻译官的角色,我们编写出的Java程序,是不能够被操作系统所直接识别的,这时候J ...
- hdu 5776 抽屉定理
sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submiss ...
- PTA——黑洞数
PTA 7-44 黑洞数 我的程序,一个用例通不过 #include<stdio.h> void sort(int *a,int n); int main() { ; scanf(&quo ...
- Window系统下搭建GIT本地服务器
转载:https://blog.csdn.net/qwer971211/article/details/71156055
- 编译安装和apt安装Nginx1.14.0
安装依赖 yum -y install gcc gcc-c++yum -y install zlib zlib-devel openssl openssl-devel pcre-devel 在Ubun ...
- 使用SURF::create()以后报错无法解析
理论上,如果在cmake中勾选了Build_opencv_world.OPENCV_ENABLE_NONFREE以及选择了OPENCV_EXTRA_MODULES_PATH三项后,再编译INSTALL ...
- 《DSP using MATLAB》Problem 7.13
代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output In ...