decode-string
https://leetcode.com/problems/decode-string/ public class Solution { private String s; private int newPos; public String decodeString(String ins) { s = '.' + ins + ']'; newPos = 0; String outStr = impl(1, 0); return outStr.substring(1, outStr.length()); } private String impl(int prefix, int startPos) { int base = 0; String baseStr = ""; String outStr = ""; for (int i=startPos; i<s.length(); i++) { char ch = s.charAt(i); if (ch == '[') { int tmpPos = i+1; baseStr += impl(base, tmpPos); i = newPos; base = 0; } else if (ch == ']') { for (int j=0; j<prefix; j++) { outStr += baseStr; } // At begin, use i+1, is wrong, // because in each loop there's i++ newPos = i; return outStr; } else if (!Character.isDigit(ch)){ baseStr += ch; } else { base = base * 10 + ch - '0'; } } return outStr; } }
分类:
leetcode
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!