leetcode.394 Decode String
来源:互联网 发布:新日铁住金软件上海 编辑:程序博客网 时间:2024/06/13 03:02
class Solution {
public:
string decodeString(string s) {
if(s.size()==0)
return"";
stack<char> a;
for(int i=0;i<=s.size()-1;i++)
{
if(s[i]>='0'&&s[i]<='9')
a.push(s[i]);
if(s[i]=='[')
a.push(s[i]);
if(s[i]>='a'&&s[i]<='z')
a.push(s[i]);
if(s[i]==']')
{
string str;
char c=a.top();
a.pop();
while(c!='[')
{
str=c+str;
c=a.top();
a.pop();
}
int num=0;
int l=1;
while(!a.empty())
{
if(a.top()>='0'&&a.top()<='9')
{
num=num+l*(a.top()-'0');
a.pop();
l*=10;
}
else
break;
}
string p=str;
for(int i=1;i<=num-1;i++)
str=str+p;
for(int i=0;i<=str.size()-1;i++)
a.push(str[i]);
}
}
string res;
while(!a.empty())
{
res=a.top()+res;
a.pop();
}
return res;
}
};
- LeetCode[394] Decode String
- leetcode-394-Decode String
- leetcode(394). Decode String
- leetcode.394 Decode String
- LeetCode.394 Decode String
- LeetCode #394 - Decode String -Medium
- LeetCode 394 Decode String 题解
- [Leetcode-394]【Stack】Decode String
- [C语言][LeetCode][394]Decode String
- Leetcode算法学习日志-394 Decode String
- 【Leetcode】394. Decode String
- [Leetcode] Decode String
- 【leetcode】394. Decode String
- LeetCode: Decode String
- leetcode ----394. Decode String
- [leetcode] 394. Decode String
- [Leetcode]394. Decode String
- Leetcode Decode String
- UVALive
- 幻灯片转换为一页多张讲义打印格式
- 事务
- 大家设计数据库时是否使用外键
- Spring Boot 读取配置文件的几种方式
- leetcode.394 Decode String
- javascript作用域与作用域链、闭包、对象创建模式、继承模式
- LZW算法 golang实现
- CentOS 6.5 中 Yum 方法安装 MySQL 5.7 完整步骤
- C语言位运算符:与、或、异或、取反、左移与右移详细介绍
- toast和menu的使用
- Hibernate与mybatis的区别
- 贪心算法总结
- 信息论实验-通信系统仿真(C++)