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 保证为正整数. 你可 ...
随机推荐
- 自动化测试-2.seleniumIDE
一.安装步骤 1. 打开Firefox浏览器 2. 打开https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/versions/,点击 ...
- VS使用Nuget教程详解 Visual studio 安装第三方的组件库
首先说明Nuget是什么呢?它的官方是:https://www.nuget.org/ 官方主页的介绍如下: What is NuGet? NuGet is the package manager fo ...
- ES6 用Promise对象实现的 Ajax 操作
下面是一个用Promise对象实现的 Ajax 操作的例子. const getJSON = function(url) { const promise = new Promise(function( ...
- 实验楼高级bash脚本编程指南 挑战:简单的热身
传送门:https://www.shiyanlou.com/courses/running# 步骤一 新建一个 test.sh 输出 Hello Shiyanlou! 步骤二 复制 test.sh 为 ...
- Date.parse()转化日期为时间戳,ios与Android兼容写法
把固定格式日期转化为时间戳: //格式化当地日期 new Date('2017-11-11 0:0:0') //结果为:Sat Nov 11 2017 00:00:00 GMT+0800 (中国标准时 ...
- 选择器(ID选择器)
ID选择器: 为HTML标签添加ID属性: <p id="p1">内容1</p> <p id="p2">内容2</p& ...
- js 数字随机滚动(数字递增)
HTML: <div class="textMon"> <img src="./img/20180830160315.png" alt=&qu ...
- 如何在Python中使用ZeroMQ和Docker构建微服务架构
@Container容器技术大会将于6月4日在上海光大会展中心国际大酒店举办,来自携程.PPTV.蚂蚁金服.京东.浙江移动.海尔电器.唯品会.eBay.道富银行.麻袋理财等公司的技术负责人将带来实践经 ...
- 什么是web前端开发?
Web前端开发工程师,主要职责是利用(X)HTML/CSS/JavaScript/Flash等各种Web技术进行客户端产品的开发.完成客户端程序(也就是浏览器端)的开发,开发JavaScript以及F ...
- 关于set_input_delay的用法分析
关于set_input_delay的用法分析 数据分为了系统同步和源同步: 对于下降沿采集数据的情况,当下降沿时钟延迟dv_afe到达无效数据最左端时,图中1位置,为最小延时,即采集不到有效数据的临界 ...