Back

题目

非负整数 num 转换为其对应的英文表示。

示例 1:

输入:num = 123
输出:"One Hundred Twenty Three"
text

示例 2:

输入:num = 12345
输出:"Twelve Thousand Three Hundred Forty Five"
text

示例 3:

输入:num = 1234567
输出:"One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
text

示例 4:


输入:num = 1234567891
输出:"One Billion Two Hundred Thirty Four Million Five Hundred Sixty Seven Thousand Eight Hundred Ninety One"
text

提示

0 <= num <= 231 - 1

来源:力扣(LeetCode)

链接:https://leetcode-cn.com/problems/integer-to-english-words

著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。

题解

英文表示为三个一组,如 123_456_789 为 123 百万 456 千 789 。根据范围提示,最大约为 21 亿, 即 2 十亿(Billion)。因此有以下代码,实际上还可以再抽象一下,但是我没再改。

[LeetCode] 273. 整数转换英文表示
https://www.ftls.xyz/posts/lr273/
Author 恐咖兵糖
Published at
Copyright CC BY-NC-SA 4.0