当前位置:网站首页>2022-02-14 (394. String decoding)
2022-02-14 (394. String decoding)
2022-07-03 04:17:00 【TickTick123】
class Solution {
public String decodeString(String s) {
StringBuilder res = new StringBuilder();
int multi = 0;
Stack<Integer> stack_multi = new Stack<>();
Stack<String> stack_res = new Stack<>();
for(Character c : s.toCharArray()) {
if(c == '[') {
stack_multi.push(multi);
stack_res.push(res.toString());
multi = 0;
res = new StringBuilder();
}
else if(c == ']') {
StringBuilder tmp = new StringBuilder();
int cur_multi = stack_multi.pop();
for(int i = 0; i < cur_multi; i++) tmp.append(res);
res = new StringBuilder(stack_res.pop() + tmp);
}
else if(c >= '0' && c <= '9') multi = multi * 10 + Integer.parseInt(c + "");
else res.append(c);
}
return res.toString();
}
}
边栏推荐
- js/ts底层实现双击事件
- 一名外包仔的2022年中总结
- vulnhub HA: Natraj
- QSAR model establishment script based on pytoch and rdkit
- 2022 beautician (intermediate) new version test questions and beautician (intermediate) certificate examination
- xrandr修改分辨率與刷新率
- [set theory] inclusion exclusion principle (including examples of exclusion principle)
- Solve BP Chinese garbled code
- 金仓数据库KingbaseES 插件kdb_exists_expand
- Interface embedded in golang struct
猜你喜欢
会员积分商城系统的功能介绍
Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended
Pdf editing tool movavi pdfchef 2022 direct download
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
CVPR 2022 | Dalian Institute of technology proposes a self calibration lighting framework for low light level image enhancement of real scenes
arthas watch 抓取入参的某个字段/属性
Arduino application development - LCD display GIF dynamic diagram
vulnhub HA: Natraj
Which code editor is easy to use? Code editing software recommendation
Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
随机推荐
Classes in TS
Basic MySQL operations
金仓数据库KingbaseES 插件kdb_exists_expand
『期末复习』16/32位微处理器(8086)基本寄存器
Reflection and planning of a sophomore majoring in electronic information engineering
QSAR model establishment script based on pytoch and rdkit
BMZCTF simple_ pop
会员积分商城系统的功能介绍
sklearn数据预处理
金仓数据库KingbaseES 插件kdb_database_link
DAPP for getting started with eth
[no title] 2022 chlorination process examination content and free chlorination process examination questions
Causal AI, a new paradigm for industrial upgrading of the next generation of credible AI?
Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
[set theory] ordered pair (ordered pair | ordered triple | ordered n ancestor)
JS实现图片懒加载
Deep dive kotlin synergy (20): build flow
[mathematical logic] predicate logic (judge whether the first-order predicate logic formula is true or false | explain | example | predicate logic formula type | forever true | forever false | satisfi
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
Application of I2C protocol of STM32F103 (read and write EEPROM)