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)
}
相关推荐
DdddJMs__1354 分钟前
C语言 | Leetcode C语言题解之第415题字符串相加
c语言·leetcode·题解
gopher951115 分钟前
go/函数
开发语言·golang
gopher951141 分钟前
go语言网络编程
开发语言·网络·golang
ZShiJ1 小时前
【题解】—— LeetCode一周小结38
算法·leetcode·职场和发展
Ddddddd_1582 小时前
C++ | Leetcode C++题解之第419题棋盘上的战舰
c++·leetcode·题解
小胡不加班2 小时前
2024.09.22 leetcode 每日一题
算法·leetcode·职场和发展
DdddJMs__1352 小时前
C语言 | Leetcode C语言题解之第419题棋盘上的战舰
c语言·leetcode·题解
程序猿练习生3 小时前
C++速通LeetCode中等第25题-验证二叉搜索树(中序遍历堆栈迭代法)
开发语言·c++·leetcode
GoFly开发者4 小时前
Golang开发的OCR-身份证号码识别(不依赖第三方)
开发语言·golang·ocr·go语言身份证识别