Golang | Leetcode Golang题解之第423题从英文中重建数字

题目:

题解:

Go 复制代码
func originalDigits(s string) string {
    c := map[rune]int{}
    for _, ch := range s {
        c[ch]++
    }

    cnt := [10]int{}
    cnt[0] = c['z']
    cnt[2] = c['w']
    cnt[4] = c['u']
    cnt[6] = c['x']
    cnt[8] = c['g']

    cnt[3] = c['h'] - cnt[8]
    cnt[5] = c['f'] - cnt[4]
    cnt[7] = c['s'] - cnt[6]

    cnt[1] = c['o'] - cnt[0] - cnt[2] - cnt[4]

    cnt[9] = c['i'] - cnt[5] - cnt[6] - cnt[8]

    ans := []byte{}
    for i, c := range cnt {
        ans = append(ans, bytes.Repeat([]byte{byte('0' + i)}, c)...)
    }
    return string(ans)
}
相关推荐
Scabbards_8 小时前
面试Leetcode - Heap 堆
java·leetcode·面试
ValhallaCoder11 小时前
Leetcode-hot100(2026.08.17)
python·算法·leetcode
xcLeigh11 小时前
Go入门:无类型常量与类型常量的区别
服务器·开发语言·golang
泡沫冰@11 小时前
GO 语言基础
开发语言·算法·golang
青 春 记 忆15 小时前
LeetCode 104. 二叉树的最大深度|Python 解法详解
python·算法·leetcode
骇客野人16 小时前
电商商城微服务架构设计方案(SpringCloud/Go+Vue3+MySQL+ES+RocketMQ)
spring cloud·微服务·golang
码农大叔的博客17 小时前
golang示例:for九九乘法表
开发语言·算法·golang
圣殿骑士-Khtangc17 小时前
Go-sync-Pool对象池最佳实践与源码分析
golang
互联网中的一颗神经元18 小时前
01. Go 内存管理全景架构
java·jvm·golang
有脚就行18 小时前
第24篇-Go-gRPC推理服务-高性能跨语言通信
开发语言·人工智能·后端·golang