reconstruct-original-digits-from-english(好)
https://leetcode.com/problems/reconstruct-original-digits-from-english/ //https://discuss.leetcode.com/topic/63386/one-pass-o-n-java-solution-simple-and-clear public class Solution { // zero one two three four five six seven eight nine ten // z 0 // e 0 1 3 3 5 7 7 8 9 // r 0 3 4 // o 0 1 2 4 // n 1 7 9 9 // t 2 3 8 // w 2 // h 3 8 // f 4 5 // u 4 // i 5 6 8 9 // v 5 7 // s 6 7 // x 6 // g 8 public String originalDigits(String s) { // 太牛了,开始我也想到统计,但是想到删除字符串那些复杂的操作上面去了 int[] counts = new int[10]; for (int i=0; i<s.length(); i++) { char ch = s.charAt(i); if (ch == 'z') counts[0]++; if (ch == 'u') counts[4]++; if (ch == 'w') counts[2]++; if (ch == 'x') counts[6]++; if (ch == 'g') counts[8]++; if (ch == 'h') counts[3]++; // 3, 8 if (ch == 's') counts[7]++; // 6, 7 if (ch == 'f') counts[5]++; // 4, 5 if (ch == 'o') counts[1]++; // 0, 1, 2, 4 if (ch == 'i') counts[9]++; // 5, 6, 8, 9 } counts[3] -= counts[8]; counts[7] -= counts[6]; counts[5] -= counts[4]; counts[1] -= counts[0] + counts[2] + counts[4]; counts[9] -= counts[5] + counts[6] + counts[8]; StringBuilder sb = new StringBuilder(); for (int i=0; i<10; i++) { for (int j=0; j<counts[i]; j++) { sb.append(i); } } return sb.toString(); } }
【推荐】国内首个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 让容器管理更轻松!