当前位置:网站首页>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();
}
}
边栏推荐
- MySQL field userid comma separated save by userid query
- leetcode:297. Serialization and deserialization of binary tree
- JS realizes lazy loading of pictures
- Mila、渥太华大学 | 用SE(3)不变去噪距离匹配进行分子几何预训练
- 服务器无法远程连接原因分析
- sklearn数据预处理
- [home push IMessage] software installation virtual host rental tothebuddy delay
- MongoDB 慢查询语句优化分析策略
- [Apple Photo Album push] IMessage group anchor local push
- js实现在可视区内,文字图片动画效果
猜你喜欢
【刷题篇】多数元素(超级水王问题)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
Pdf editing tool movavi pdfchef 2022 direct download
Two points -leetcode-540 A single element in an ordered array
Busycal latest Chinese version
Bisher - based on SSM pet adoption center
Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended
Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
Basic MySQL operations
随机推荐
Nat. Comm. | 使用Tensor-cell2cell对细胞通讯进行环境感知去卷积
vulnhub HA: Natraj
"Designer universe" argument: Data Optimization in the design field is finally reflected in cost, safety and health | chinabrand.com org
『期末复习』16/32位微处理器(8086)基本寄存器
Deep dive kotlin synergy (20): build flow
Pdf editing tool movavi pdfchef 2022 direct download
用户体验五要素
Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
JS实现图片懒加载
540. Single element in ordered array
Redis persistence principle
sklearn数据预处理
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
Interface in TS
[untitled] 2022 safety production supervisor examination question bank and simulated safety production supervisor examination questions
跨境电商多商户系统怎么选
拆一辆十万元的比亚迪“元”,快来看看里面的有哪些元器件。
The time has come for the domestic PC system to complete the closed loop and replace the American software and hardware system
How do you use lodash linking function- How do you chain functions using lodash?
Daily question - ugly number