Integer to English Words
HardP3Coding
Convert the non-negative integer num to its English words. Use the usual American style: no and, words separated by a single space, no leading or trailing space, and Thousand, Million, Billion for the groups. Words are capitalised (One Hundred Twenty Three).
For 0 return Zero.
Example 1
- Input
- num = 123
- Output
- "One Hundred Twenty Three"
Example 2
- Input
- num = 12345
- Output
- "Twelve Thousand Three Hundred Forty Five"
Example 3
- Input
- num = 1234567
- Output
- "One Million Two Hundred Thirty Four Thousand Five Hundred Sixty Seven"
Constraints
- 0 <= num <= 2^31 - 1
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 16. ⌘Enter runs, ⌘⇧Enter submits.