/
githubmirror
/
LeetCodeAnimation
Обзор
Документация
Войти
/
githubmirror
/
LeetCodeAnimation
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
problems/0394-Decode-String/Code/1.java
34 строки
1 KB
吴至波
docs: organize assets and add animation previews
10 июн 2026, 10:57
10 июн 2026, 10:57
3711846
Код
Авторство
О чём код?
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 (int i = 0; i < s.length(); i++) { char c = s.charAt(i); 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 j = 0; j < cur_multi; j++){ tmp.append(res); } res = new StringBuilder(stack_res.pop() + tmp); } else if(c >= '0' && c <= '9'){ multi = multi * 10 + (c - '0'); } else{ res.append(c); } } return res.toString(); } }