当前位置:网站首页>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();
}
}
边栏推荐
- 540. Single element in ordered array
- Two points -leetcode-540 A single element in an ordered array
- 金仓数据库KingbaseES 插件kdb_exists_expand
- Redraw and reflow
- IPv6 foundation construction experiment
- [Blue Bridge Road -- bug free code] DS18B20 temperature reading code analysis
- Analysis of the reason why the server cannot connect remotely
- CVPR 2022 | 大連理工提出自校准照明框架,用於現實場景的微光圖像增强
- [graduation season · aggressive technology Er] Confessions of workers
- vim 的实用操作
猜你喜欢

Esp32 series (3): GPIO learning (take simple GPIO input and output, ADC, DAC as examples)

中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》

arthas watch 抓取入参的某个字段/属性

Two points -leetcode-540 A single element in an ordered array

"Final review" 16/32-bit microprocessor (8086) basic register

Nat. Comm. | use tensor cell2cell to deconvolute cell communication with environmental awareness

金仓KFS数据双向同步场景部署

What are the Bluetooth headsets with good sound quality in 2022? Inventory of four high-quality Bluetooth headsets

Busycal latest Chinese version

2022-07-02: what is the output of the following go language code? A: Compilation error; B:Panic; C:NaN。 package main import “fmt“ func main() { var a =
随机推荐
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
xrandr修改分辨率與刷新率
sklearn数据预处理
【刷题篇】多数元素(超级水王问题)
Sklearn data preprocessing
中移物联网OneOS与OneNET入选《2021年物联网示范项目名单》
Which Bluetooth headset is cost-effective? Four Bluetooth headsets with high cost performance are recommended
eth入门之简介
540. Single element in ordered array
QSAR model establishment script based on pytoch and rdkit
ZIP文件的导出
[fxcg] market analysis today
Interaction free shell programming
Competitive product analysis and writing
Mila, University of Ottawa | molecular geometry pre training with Se (3) invariant denoising distance matching
leetcode:297. Serialization and deserialization of binary tree
Nodejs Foundation: shallow chat URL and querystring module
Design and implementation of kubelet garbage collection mechanism to protect nodes from being preempted by containers image GC high threshold
重绘和回流
Pdf editing tool movavi pdfchef 2022 direct download